diff options
| author | 2024-05-13 12:44:35 +0200 | |
|---|---|---|
| committer | 2024-05-13 12:44:35 +0200 | |
| commit | 4f57a46075fc38cffd479ab76b2ea56e9b626926 (patch) | |
| tree | d6d1ed24ae44dce25a8f05c3b06dfcb9c695d709 /app/Models/DatabaseDAO.php | |
| parent | e0cc121c7a556126b6c4968cb9efac47ee1382b5 (diff) | |
Auto-update 5038 (#6279)
* Auto-update 5038
https://github.com/FreshRSS/FreshRSS/pull/5038
* PostgreSQL
* Draft for MySQL
* More draft MySQL
* Finalise
* A bit more robust
Diffstat (limited to 'app/Models/DatabaseDAO.php')
| -rw-r--r-- | app/Models/DatabaseDAO.php | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/app/Models/DatabaseDAO.php b/app/Models/DatabaseDAO.php index ec5500d3e..d0938ca62 100644 --- a/app/Models/DatabaseDAO.php +++ b/app/Models/DatabaseDAO.php @@ -232,8 +232,29 @@ SQL; $catDAO->resetDefaultCategoryName(); include_once(APP_PATH . '/SQL/install.sql.' . $this->pdo->dbType() . '.php'); - if (!empty($GLOBALS['SQL_UPDATE_MINOR']) && $this->pdo->exec($GLOBALS['SQL_UPDATE_MINOR']) === false) { - Minz_Log::error('SQL error ' . __METHOD__ . json_encode($this->pdo->errorInfo())); + if (!empty($GLOBALS['SQL_UPDATE_MINOR'])) { + $sql = $GLOBALS['SQL_UPDATE_MINOR']; + $isMariaDB = false; + + if ($this->pdo->dbType() === 'mysql') { + $dbVersion = $this->fetchValue('SELECT version()') ?? ''; + $isMariaDB = stripos($dbVersion, 'MariaDB') !== false; // MariaDB includes its name in version, but not MySQL + if (!$isMariaDB) { + // MySQL does not support `DROP INDEX IF EXISTS` yet https://dev.mysql.com/doc/refman/8.3/en/drop-index.html + // but MariaDB does https://mariadb.com/kb/en/drop-index/ + $sql = str_replace('DROP INDEX IF EXISTS', 'DROP INDEX', $sql); + } + } + + if ($this->pdo->exec($sql) === false) { + $info = $this->pdo->errorInfo(); + if ($this->pdo->dbType() === 'mysql' && + !$isMariaDB && !empty($info[2]) && (stripos($info[2], "Can't DROP ") !== false)) { + // Too bad for MySQL, but ignore error + return; + } + Minz_Log::error('SQL error ' . __METHOD__ . json_encode($this->pdo->errorInfo())); + } } } |
