diff options
| author | 2023-09-12 10:43:14 +0200 | |
|---|---|---|
| committer | 2023-09-12 10:43:14 +0200 | |
| commit | f050a94b48499286abfb4b69f3bcb3dee5f9ea2d (patch) | |
| tree | 1614483dd53294500825d036a52d4d4a5170bb23 /app/Models | |
| parent | f5aba79d147532990cbf321e311e06e3f7bea0d1 (diff) | |
SQL: clean old auto-updates (#5649)
Should help with some DB lock issues.
Complete https://github.com/FreshRSS/FreshRSS/pull/3558 after https://github.com/FreshRSS/FreshRSS/pull/5625 already cherry-picked from it.
* Removed auto-update of MySQL GUID case sensitivity
https://github.com/FreshRSS/FreshRSS/pull/2078
* Contributed to a DB lock in https://github.com/FreshRSS/FreshRSS/issues/5008
Also removed the following non-problematic auto-updates, simply because they were older than the above ones
* Auto-create custom labels (1.12.0) https://github.com/FreshRSS/FreshRSS/pull/2027
* Auto-add JSON column for feeds (1.11.0) https://github.com/FreshRSS/FreshRSS/pull/1838
* Auto-create temporary tables (1.7.0) https://github.com/FreshRSS/FreshRSS/pull/1470
Diffstat (limited to 'app/Models')
| -rw-r--r-- | app/Models/DatabaseDAO.php | 18 | ||||
| -rw-r--r-- | app/Models/EntryDAO.php | 28 | ||||
| -rw-r--r-- | app/Models/EntryDAOPGSQL.php | 8 | ||||
| -rw-r--r-- | app/Models/EntryDAOSQLite.php | 13 | ||||
| -rw-r--r-- | app/Models/FeedDAO.php | 4 | ||||
| -rw-r--r-- | app/Models/TagDAO.php | 48 | ||||
| -rw-r--r-- | app/Models/TagDAOSQLite.php | 11 | ||||
| -rw-r--r-- | app/Models/UserDAO.php | 2 |
8 files changed, 2 insertions, 130 deletions
diff --git a/app/Models/DatabaseDAO.php b/app/Models/DatabaseDAO.php index 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.php index 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.php index 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.php index 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.php index 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.0 return $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.php index 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.php index 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.php index 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; |
