diff options
| author | 2019-11-06 15:16:00 +0100 | |
|---|---|---|
| committer | 2019-11-06 15:16:00 +0100 | |
| commit | 22030155f8fd5cab102ddd897a914cf1a0ffd183 (patch) | |
| tree | 1af332589e778645dc80cb06de8c45261e3eecdd /lib | |
| parent | 12cdd2cdf6d493a8bd110d1ae310288a0a47afa0 (diff) | |
Fix database autocreate at install (#2635)
* Fix database autocreate at install
Several bugs prevented the auto-creation of the database in Web and CLI
installs.
Fix
https://github.com/YunoHost-Apps/freshrss_ynh/issues/84#issuecomment-549818408
* initDb
https://github.com/FreshRSS/FreshRSS/pull/2635#discussion_r343107795
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Minz/ModelPdo.php | 4 | ||||
| -rw-r--r-- | lib/lib_install.php | 21 |
2 files changed, 17 insertions, 8 deletions
diff --git a/lib/Minz/ModelPdo.php b/lib/Minz/ModelPdo.php index 69785c253..6eb4881dc 100644 --- a/lib/Minz/ModelPdo.php +++ b/lib/Minz/ModelPdo.php @@ -28,6 +28,9 @@ class Minz_ModelPdo { if ($currentUser === null) { $currentUser = Minz_Session::param('currentUser'); } + if ($currentUser == '') { + throw new Minz_PDOConnectionException('Current user must not be empty!', '', Minz_Exception::ERROR); + } if ($currentPdo != null) { $this->pdo = $currentPdo; return; @@ -84,7 +87,6 @@ class Minz_ModelPdo { 'Invalid database type!', $db['user'], Minz_Exception::ERROR ); - break; } self::$sharedPdo = $this->pdo; } catch (Exception $e) { diff --git a/lib/lib_install.php b/lib/lib_install.php index ed361eb39..5ea1b4d2b 100644 --- a/lib/lib_install.php +++ b/lib/lib_install.php @@ -78,21 +78,28 @@ function generateSalt() { return sha1(uniqid(mt_rand(), true).implode('', stat(__FILE__))); } -function checkDb() { +function initDb() { $conf = FreshRSS_Context::$system_conf; $db = $conf->db; if (empty($db['pdo_options'])) { $db['pdo_options'] = []; } $db['pdo_options'][PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; - $dbBase = isset($db['base']) ? $db['base'] : ''; + $conf->db = $db; //TODO: Remove this Minz limitation "Indirect modification of overloaded property" - $db['base'] = ''; //First connection without database name to create the database - Minz_ModelPdo::$usesSharedPdo = false; - $databaseDAO = FreshRSS_Factory::createDatabaseDAO(); - $databaseDAO->create(); + if ($db['type'] !== 'sqlite') { + Minz_ModelPdo::$usesSharedPdo = false; + $dbBase = isset($db['base']) ? $db['base'] : ''; + $db['base'] = ''; + $conf->db = $db; + //First connection without database name to create the database + $databaseDAO = FreshRSS_Factory::createDatabaseDAO(); + $db['base'] = $dbBase; + $conf->db = $db; + $databaseDAO->create(); + } - $db['base'] = $dbBase; //New connection with the database name + //New connection with the database name $databaseDAO = FreshRSS_Factory::createDatabaseDAO(); Minz_ModelPdo::$usesSharedPdo = true; return $databaseDAO->testConnection(); |
