A free, self-hostable news aggregator…
SQL: clean old auto-updates (#5649)
Alexandre Alapetitef050a94b4849
diff --git a/app/Models/DatabaseDAO.php b/app/Models/DatabaseDAO.phpindex ea12bab8e..416c1fb65 100644--- a/app/Models/DatabaseDAO.php+++ b/app/Models/DatabaseDAO.php@@ -204,27 +204,9 @@ SQL;return $ok;}- public function ensureCaseInsensitiveGuids(): bool {- $ok = true;- if ($this->pdo->dbType() === 'mysql') {- include(APP_PATH . '/SQL/install.sql.mysql.php');-- $ok = false;- try {- $ok = $this->pdo->exec($GLOBALS['SQL_UPDATE_GUID_LATIN1_BIN']) !== false; //FreshRSS 1.12- } catch (Exception $e) {- $ok = false;- Minz_Log::error(__METHOD__ . ' error: ' . $e->getMessage());- }- }- return $ok;- }-public function minorDbMaintenance(): void {$catDAO = FreshRSS_Factory::createCategoryDao();$catDAO->resetDefaultCategoryName();-- $this->ensureCaseInsensitiveGuids();}private static function stdError(string $error): bool {diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.phpindex 8306320a0..8a006f802 100644--- a/app/Models/EntryDAO.php+++ b/app/Models/EntryDAO.php@@ -26,26 +26,6 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {return str_replace('INSERT INTO ', 'INSERT IGNORE INTO ', $sql);}- //TODO: Move the database auto-updates to DatabaseDAO- protected function createEntryTempTable(): bool {- $ok = false;- $hadTransaction = $this->pdo->inTransaction();- if ($hadTransaction) {- $this->pdo->commit();- }- try {- require(APP_PATH . '/SQL/install.sql.' . $this->pdo->dbType() . '.php');- Minz_Log::warning('SQL CREATE TABLE entrytmp...');- $ok = $this->pdo->exec($GLOBALS['SQL_CREATE_TABLE_ENTRYTMP'] . $GLOBALS['SQL_CREATE_INDEX_ENTRY_1']) !== false;- } catch (Exception $ex) {- Minz_Log::error(__method__ . ' error: ' . $ex->getMessage());- }- if ($hadTransaction) {- $this->pdo->beginTransaction();- }- return $ok;- }-private function updateToMediumBlob(): bool {if ($this->pdo->dbType() !== 'mysql') {return false;@@ -96,14 +76,6 @@ SQL;}}}- if ($errorInfo[0] === FreshRSS_DatabaseDAO::ER_BAD_TABLE_ERROR) {- if (stripos($errorInfo[2], 'tag') !== false) {- $tagDAO = FreshRSS_Factory::createTagDao();- return $tagDAO->createTagTable(); //v1.12.0- } elseif (stripos($errorInfo[2], 'entrytmp') !== false) {- return $this->createEntryTempTable(); //v1.7.0- }- }}if (isset($errorInfo[1])) {if ($errorInfo[1] == FreshRSS_DatabaseDAO::ER_DATA_TOO_LONG) {diff --git a/app/Models/EntryDAOPGSQL.php b/app/Models/EntryDAOPGSQL.phpindex 4c3c50056..06a32712a 100644--- a/app/Models/EntryDAOPGSQL.php+++ b/app/Models/EntryDAOPGSQL.php@@ -29,14 +29,6 @@ class FreshRSS_EntryDAOPGSQL extends FreshRSS_EntryDAOSQLite {}}}- if ($errorInfo[0] === FreshRSS_DatabaseDAOPGSQL::UNDEFINED_TABLE) {- if (stripos($errorInfo[2], 'tag') !== false) {- $tagDAO = FreshRSS_Factory::createTagDao();- return $tagDAO->createTagTable(); //v1.12.0- } elseif (stripos($errorInfo[2], 'entrytmp') !== false) {- return $this->createEntryTempTable(); //v1.7.0- }- }}return false;}diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.phpindex 6abf31a5b..b913b882d 100644--- a/app/Models/EntryDAOSQLite.php+++ b/app/Models/EntryDAOSQLite.php@@ -32,19 +32,6 @@ class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO {}}}- if ($tableInfo = $this->pdo->query("SELECT sql FROM sqlite_master where name='tag'")) {- $showCreate = $tableInfo->fetchColumn();- if (is_string($showCreate) && stripos($showCreate, 'tag') === false) {- $tagDAO = FreshRSS_Factory::createTagDao();- return $tagDAO->createTagTable(); //v1.12.0- }- }- if ($tableInfo = $this->pdo->query("SELECT sql FROM sqlite_master where name='entrytmp'")) {- $showCreate = $tableInfo->fetchColumn();- if (is_string($showCreate) && stripos($showCreate, 'entrytmp') === false) {- return $this->createEntryTempTable(); //v1.7.0- }- }return false;}diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.phpindex 5461ba4ed..508d38bfc 100644--- a/app/Models/FeedDAO.php+++ b/app/Models/FeedDAO.php@@ -10,8 +10,6 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {try {if ($name === 'kind') { //v1.20.0return $this->pdo->exec('ALTER TABLE `_feed` ADD COLUMN kind SMALLINT DEFAULT 0') !== false;- } elseif ($name === 'attributes') { //v1.11.0- return $this->pdo->exec('ALTER TABLE `_feed` ADD COLUMN attributes TEXT') !== false;}} catch (Exception $e) {Minz_Log::error(__method__ . ' error: ' . $e->getMessage());@@ -24,7 +22,7 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {if (isset($errorInfo[0])) {if ($errorInfo[0] === FreshRSS_DatabaseDAO::ER_BAD_FIELD_ERROR || $errorInfo[0] === FreshRSS_DatabaseDAOPGSQL::UNDEFINED_COLUMN) {$errorLines = explode("\n", $errorInfo[2], 2); // The relevant column name is on the first line, other lines are noise- foreach (['attributes', 'kind'] as $column) {+ foreach (['kind'] as $column) {if (stripos($errorLines[0], $column) !== false) {return $this->addColumn($column);}diff --git a/app/Models/TagDAO.php b/app/Models/TagDAO.phpindex 80a0e7688..b41a6de72 100644--- a/app/Models/TagDAO.php+++ b/app/Models/TagDAO.php@@ -6,42 +6,6 @@ class FreshRSS_TagDAO extends Minz_ModelPdo {return 'IGNORE';}- public function createTagTable(): bool {- $ok = false;- $hadTransaction = $this->pdo->inTransaction();- if ($hadTransaction) {- $this->pdo->commit();- }- try {- require(APP_PATH . '/SQL/install.sql.' . $this->pdo->dbType() . '.php');-- Minz_Log::warning('SQL ALTER GUID case sensitivity…');- $databaseDAO = FreshRSS_Factory::createDatabaseDAO();- $databaseDAO->ensureCaseInsensitiveGuids();-- Minz_Log::warning('SQL CREATE TABLE tag…');- $ok = $this->pdo->exec($GLOBALS['SQL_CREATE_TABLE_TAGS']) !== false;- } catch (Exception $e) {- Minz_Log::error('FreshRSS_EntryDAO::createTagTable error: ' . $e->getMessage());- }- if ($hadTransaction) {- $this->pdo->beginTransaction();- }- return $ok;- }-- /** @param array<string> $errorInfo */- protected function autoUpdateDb(array $errorInfo): bool {- if (isset($errorInfo[0])) {- if ($errorInfo[0] === FreshRSS_DatabaseDAO::ER_BAD_TABLE_ERROR || $errorInfo[0] === FreshRSS_DatabaseDAOPGSQL::UNDEFINED_TABLE) {- if (stripos($errorInfo[2], 'tag') !== false) {- return $this->createTagTable(); //v1.12.0- }- }- }- return false;- }-/*** @param array{'id'?:int,'name':string,'attributes'?:array<string,mixed>} $valuesTmp* @return int|false@@ -244,9 +208,6 @@ SQL;return self::daoToTag($res);} else {$info = $this->pdo->errorInfo();- if ($this->autoUpdateDb($info)) {- return $this->listTags($precounts);- }Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info));return false;}@@ -284,9 +245,6 @@ SQL;return (int)$res[0]['count'];}$info = $this->pdo->errorInfo();- if ($this->autoUpdateDb($info)) {- return $this->count();- }Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info));return -1;}@@ -359,9 +317,6 @@ SQL;return $lines;}$info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();- if ($this->autoUpdateDb($info)) {- return $this->getTagsForEntry($id_entry);- }Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info));return false;}@@ -415,9 +370,6 @@ SQL;return $stm->fetchAll(PDO::FETCH_ASSOC);}$info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();- if ($this->autoUpdateDb($info)) {- return $this->getTagsForEntries($entries);- }Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info));return false;}diff --git a/app/Models/TagDAOSQLite.php b/app/Models/TagDAOSQLite.phpindex 50683cf84..f1921c9f0 100644--- a/app/Models/TagDAOSQLite.php+++ b/app/Models/TagDAOSQLite.php@@ -6,15 +6,4 @@ class FreshRSS_TagDAOSQLite extends FreshRSS_TagDAO {return 'OR IGNORE';}- /** @param array<string> $errorInfo */- protected function autoUpdateDb(array $errorInfo): bool {- if ($tableInfo = $this->pdo->query("SELECT sql FROM sqlite_master where name='tag'")) {- $showCreate = $tableInfo->fetchColumn();- if (is_string($showCreate) && stripos($showCreate, 'tag') === false) {- return $this->createTagTable(); //v1.12.0- }- }- return false;- }-}diff --git a/app/Models/UserDAO.php b/app/Models/UserDAO.phpindex 8ba50cc29..0961da82e 100644--- a/app/Models/UserDAO.php+++ b/app/Models/UserDAO.php@@ -6,7 +6,7 @@ class FreshRSS_UserDAO extends Minz_ModelPdo {require(APP_PATH . '/SQL/install.sql.' . $this->pdo->dbType() . '.php');try {- $sql = $GLOBALS['SQL_CREATE_TABLES'] . $GLOBALS['SQL_CREATE_TABLE_ENTRYTMP'] . $GLOBALS['SQL_CREATE_TABLE_TAGS'];+ $sql = $GLOBALS['SQL_CREATE_TABLES'];$ok = $this->pdo->exec($sql) !== false; //Note: Only exec() can take multiple statements safely.} catch (Exception $e) {$ok = false;diff --git a/app/SQL/install.sql.mysql.php b/app/SQL/install.sql.mysql.phpindex b8fff170a..74fc65b19 100644--- a/app/SQL/install.sql.mysql.php+++ b/app/SQL/install.sql.mysql.php@@ -66,13 +66,7 @@ CREATE TABLE IF NOT EXISTS `_entry` (ENGINE = INNODB;INSERT IGNORE INTO `_category` (id, name) VALUES(1, "Uncategorized");-SQL;--$GLOBALS['SQL_CREATE_INDEX_ENTRY_1'] = <<<'SQL'-CREATE INDEX `entry_feed_read_index` ON `_entry` (`id_feed`,`is_read`); -- v1.7-SQL;-$GLOBALS['SQL_CREATE_TABLE_ENTRYTMP'] = <<<'SQL'CREATE TABLE IF NOT EXISTS `_entrytmp` ( -- v1.7`id` BIGINT NOT NULL,`guid` VARCHAR(760) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL,@@ -94,9 +88,7 @@ CREATE TABLE IF NOT EXISTS `_entrytmp` ( -- v1.7INDEX (`date`)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ciENGINE = INNODB;-SQL;-$GLOBALS['SQL_CREATE_TABLE_TAGS'] = <<<'SQL'CREATE TABLE IF NOT EXISTS `_tag` ( -- v1.12`id` INT NOT NULL AUTO_INCREMENT,`name` VARCHAR(63) NOT NULL,@@ -120,8 +112,3 @@ SQL;$GLOBALS['SQL_DROP_TABLES'] = <<<'SQL'DROP TABLE IF EXISTS `_entrytag`, `_tag`, `_entrytmp`, `_entry`, `_feed`, `_category`;SQL;--$GLOBALS['SQL_UPDATE_GUID_LATIN1_BIN'] = <<<'SQL'-ALTER TABLE `_entrytmp` MODIFY `guid` VARCHAR(760) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL; -- v1.12-ALTER TABLE `_entry` MODIFY `guid` VARCHAR(760) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL;-SQL;diff --git a/app/SQL/install.sql.pgsql.php b/app/SQL/install.sql.pgsql.phpindex 00a30a8c7..2149fc247 100644--- a/app/SQL/install.sql.pgsql.php+++ b/app/SQL/install.sql.pgsql.php@@ -62,13 +62,7 @@ INSERT INTO `_category` (id, name)SELECT 1, 'Uncategorized'WHERE NOT EXISTS (SELECT id FROM `_category` WHERE id = 1)RETURNING nextval('`_category_id_seq`');-SQL;-$GLOBALS['SQL_CREATE_INDEX_ENTRY_1'] = <<<'SQL'-CREATE INDEX IF NOT EXISTS `_entry_feed_read_index` ON `_entry` ("id_feed","is_read"); -- v1.7-SQL;--$GLOBALS['SQL_CREATE_TABLE_ENTRYTMP'] = <<<'SQL'CREATE TABLE IF NOT EXISTS `_entrytmp` ( -- v1.7"id" BIGINT NOT NULL PRIMARY KEY,"guid" VARCHAR(760) NOT NULL,@@ -88,9 +82,7 @@ CREATE TABLE IF NOT EXISTS `_entrytmp` ( -- v1.7UNIQUE ("id_feed","guid"));CREATE INDEX IF NOT EXISTS `_entrytmp_date_index` ON `_entrytmp` ("date");-SQL;-$GLOBALS['SQL_CREATE_TABLE_TAGS'] = <<<'SQL'CREATE TABLE IF NOT EXISTS `_tag` ( -- v1.12"id" SERIAL PRIMARY KEY,"name" VARCHAR(63) UNIQUE NOT NULL,diff --git a/app/SQL/install.sql.sqlite.php b/app/SQL/install.sql.sqlite.phpindex 8762b33eb..b353f361e 100644--- a/app/SQL/install.sql.sqlite.php+++ b/app/SQL/install.sql.sqlite.php@@ -61,13 +61,7 @@ CREATE INDEX IF NOT EXISTS entry_lastSeen_index ON `entry`(`lastSeen`); -- //v1.CREATE INDEX IF NOT EXISTS entry_feed_read_index ON `entry`(`id_feed`,`is_read`); -- v1.7INSERT OR IGNORE INTO `category` (id, name) VALUES(1, "Uncategorized");-SQL;-$GLOBALS['SQL_CREATE_INDEX_ENTRY_1'] = <<<'SQL'-CREATE INDEX IF NOT EXISTS entry_feed_read_index ON `entry`(`id_feed`,`is_read`); -- v1.7-SQL;--$GLOBALS['SQL_CREATE_TABLE_ENTRYTMP'] = <<<'SQL'CREATE TABLE IF NOT EXISTS `entrytmp` ( -- v1.7`id` BIGINT NOT NULL,`guid` VARCHAR(760) NOT NULL,@@ -88,9 +82,7 @@ CREATE TABLE IF NOT EXISTS `entrytmp` ( -- v1.7UNIQUE (`id_feed`,`guid`));CREATE INDEX IF NOT EXISTS entrytmp_date_index ON `entrytmp`(`date`);-SQL;-$GLOBALS['SQL_CREATE_TABLE_TAGS'] = <<<'SQL'CREATE TABLE IF NOT EXISTS `tag` ( -- v1.12`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,`name` VARCHAR(63) NOT NULL,