aboutsummaryrefslogtreecommitdiff
path: root/app/Models/DatabaseDAO.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2024-04-30 08:31:13 +0200
committerGravatar GitHub <noreply@github.com> 2024-04-30 08:31:13 +0200
commit329fd4bcf6504c74e3906e51c6fc2124bc09cc02 (patch)
tree11c6c56d404403eca1996e89aeb6a978b9d92237 /app/Models/DatabaseDAO.php
parent173555795adf6614dff33893b373f22542910675 (diff)
CLI database backup and restore (#6387)
* CLI database backup and restore Can also be used to migrate from one database to another (e.g. MySQL to PostgreSQL) or to ease upgrade to a major PostgreSQL version (e.g. 15 to 16). * +x * Fix some cases * Update to docker-compose-v2 * More documentation
Diffstat (limited to 'app/Models/DatabaseDAO.php')
-rw-r--r--app/Models/DatabaseDAO.php22
1 files changed, 19 insertions, 3 deletions
diff --git a/app/Models/DatabaseDAO.php b/app/Models/DatabaseDAO.php
index cdc74fa12..667cb61a2 100644
--- a/app/Models/DatabaseDAO.php
+++ b/app/Models/DatabaseDAO.php
@@ -48,6 +48,18 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo {
}
}
+ public function exits(): bool {
+ $sql = 'SELECT * FROM `_entry` LIMIT 1';
+ $stm = $this->pdo->query($sql);
+ if ($stm !== false) {
+ $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
+ if ($res !== false) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public function tablesAreCorrect(): bool {
$res = $this->fetchAssoc('SHOW TABLES');
if ($res == null) {
@@ -242,6 +254,7 @@ SQL;
}
$error = '';
+ $databaseDAO = FreshRSS_Factory::createDatabaseDAO();
$userDAO = FreshRSS_Factory::createUserDao();
$catDAO = FreshRSS_Factory::createCategoryDao();
$feedDAO = FreshRSS_Factory::createFeedDao();
@@ -259,15 +272,18 @@ SQL;
$error = 'Error: SQLite import file is not readable: ' . $filename;
} elseif ($clearFirst) {
$userDAO->deleteUser();
+ $userDAO = FreshRSS_Factory::createUserDao();
if ($this->pdo->dbType() === 'sqlite') {
//We cannot just delete the .sqlite file otherwise PDO gets buggy.
//SQLite is the only one with database-level optimization, instead of at table level.
$this->optimize();
}
} else {
- $nbEntries = $entryDAO->countUnreadRead();
- if (!empty($nbEntries['all'])) {
- $error = 'Error: Destination database already contains some entries!';
+ if ($databaseDAO->exits()) {
+ $nbEntries = $entryDAO->countUnreadRead();
+ if (isset($nbEntries['all']) && $nbEntries['all'] > 0) {
+ $error = 'Error: Destination database already contains some entries!';
+ }
}
}
break;