diff options
| author | 2025-06-06 09:56:27 +0200 | |
|---|---|---|
| committer | 2025-06-06 09:56:27 +0200 | |
| commit | f620f16e2b62cc12e8b2a155d8f764dd8bafefe8 (patch) | |
| tree | 0fdfb5bad689dc061ef1f74367e75ff46038044f | |
| parent | 4de7d0b81310c788365fd3d2ab28dfbbccb5b171 (diff) | |
Install: add test PDO typing (#7651)
fix https://github.com/FreshRSS/FreshRSS/issues/7647
| -rw-r--r-- | app/Models/DatabaseDAO.php | 12 | ||||
| -rw-r--r-- | app/install.php | 14 | ||||
| -rw-r--r-- | lib/Minz/ModelPdo.php | 6 |
3 files changed, 30 insertions, 2 deletions
diff --git a/app/Models/DatabaseDAO.php b/app/Models/DatabaseDAO.php index fe922cb82..0062c23e8 100644 --- a/app/Models/DatabaseDAO.php +++ b/app/Models/DatabaseDAO.php @@ -222,6 +222,18 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo { return str_contains($this->version(), 'MariaDB'); } + /** + * @return bool true if the database PDO driver returns typed integer values as it should, false otherwise. + */ + final public function testTyping(): bool { + $sql = 'SELECT 2 + 3'; + if (($stm = $this->pdo->query($sql)) !== false) { + $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0); + return ($res[0] ?? null) === 5; + } + return false; + } + public function size(bool $all = false): int { $db = FreshRSS_Context::systemConf()->db; diff --git a/app/install.php b/app/install.php index c2fd86370..3d835d1f1 100644 --- a/app/install.php +++ b/app/install.php @@ -234,6 +234,17 @@ function saveStep3(): bool { $ok = false; try { + Minz_ModelPdo::$usesSharedPdo = false; + $databaseDAO = FreshRSS_Factory::createDatabaseDAO(Minz_User::INTERNAL_USER); + if (!$databaseDAO->testTyping()) { + $message = 'Invalid PDO driver behaviour for selected database type!'; + if (Minz_Session::paramString('bd_type') === 'mysql') { + $message .= ' MySQL requires mysqlnd.'; + } + throw new Exception($message); + } + Minz_ModelPdo::$usesSharedPdo = true; + $ok = FreshRSS_user_Controller::createUser( Minz_Session::paramString('default_user'), '', //TODO: Add e-mail @@ -249,6 +260,7 @@ function saveStep3(): bool { $ok = false; } if (!$ok) { + checkStep(); return false; } @@ -526,7 +538,7 @@ function printStep2(): void { <p class="alert alert-success"><span class="alert-head"><?= _t('gen.short.ok') ?></span> <?= _t('install.bdd.conf.ok') ?></p> <?php } elseif ($s2['conn'] == 'ko') { ?> <p class="alert alert-error"><span class="alert-head"><?= _t('gen.short.damn') ?></span> <?= _t('install.bdd.conf.ko'), - (empty($_SESSION['bd_error']) || !is_string($_SESSION['bd_error']) ? '' : ' : ' . $_SESSION['bd_error']) ?></p> + (empty($_SESSION['bd_error']) || !is_string($_SESSION['bd_error']) ? '' : ' ' . $_SESSION['bd_error']) ?></p> <?php } ?> <h2><?= _t('install.bdd.conf') ?></h2> diff --git a/lib/Minz/ModelPdo.php b/lib/Minz/ModelPdo.php index 86f6df306..cb541a1e4 100644 --- a/lib/Minz/ModelPdo.php +++ b/lib/Minz/ModelPdo.php @@ -62,7 +62,11 @@ class Minz_ModelPdo { $this->pdo->setPrefix($db['prefix'] . $this->current_user . '_'); break; case 'sqlite': - $dsn = 'sqlite:' . DATA_PATH . '/users/' . $this->current_user . '/db.sqlite'; + if (in_array($this->current_user, [null, '', Minz_User::INTERNAL_USER], true)) { + $dsn = 'sqlite::memory:'; + } else { + $dsn = 'sqlite:' . DATA_PATH . '/users/' . $this->current_user . '/db.sqlite'; + } $this->pdo = new Minz_PdoSqlite($dsn . $dsnParams, null, null, $driver_options); $this->pdo->setPrefix(''); break; |
