A free, self-hostable news aggregator…
Fix database autocreate at install (#2635)
Alexandre Alapetite22030155f8fd
diff --git a/Docker/README.md b/Docker/README.mdindex d06016fb9..6920471df 100644--- a/Docker/README.md+++ b/Docker/README.md@@ -162,10 +162,11 @@ docker build --pull --tag freshrss/freshrss -f Docker/Dockerfile .## Command line```sh-docker exec --user apache -it freshrss php ./cli/list-users.php+docker exec --user www-data -it freshrss php ./cli/list-users.php```See the [CLI documentation](../cli/) for all the other commands.+You might have to replace `--user www-data` by `--user apache` when using our images based on Linux Alpine.## Debugging@@ -210,7 +211,7 @@ Remember not pass the `CRON_MIN` environment variable to your Docker run, to avoExample on Debian / Ubuntu: Create `/etc/cron.d/FreshRSS` with:```-7,37 * * * * root docker exec --user apache -it freshrss php ./app/actualize_script.php > /tmp/FreshRSS.log 2>&1+7,37 * * * * root docker exec --user www-data -it freshrss php ./app/actualize_script.php > /tmp/FreshRSS.log 2>&1```### Option 3) Cron as another instance of the same FreshRSS Docker imagediff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.phpindex fa0001df7..2bff50d52 100644--- a/app/Models/FeedDAO.php+++ b/app/Models/FeedDAO.php@@ -102,7 +102,9 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {'httpAuth' => $feed->httpAuth(),'attributes' => $feed->attributes(),);- if ($feed->mute() || $feed->ttl() != FreshRSS_Context::$user_conf->ttl_default) {+ if ($feed->mute() || (+ FreshRSS_Context::$user_conf != null && //When creating a new user+ $feed->ttl() != FreshRSS_Context::$user_conf->ttl_default)) {$values['ttl'] = $feed->ttl() * ($feed->mute() ? -1 : 1);}diff --git a/app/install.php b/app/install.phpindex 96bee34a1..557ae9eab 100644--- a/app/install.php+++ b/app/install.php@@ -132,7 +132,7 @@ function saveStep2() {$config_array = ['salt' => generateSalt(),'base_url' => $base_url,- 'default_user' => 'admin',+ 'default_user' => '_','db' => ['type' => $_SESSION['bd_type'],'host' => $_SESSION['bd_host'],@@ -154,12 +154,18 @@ function saveStep2() {@unlink(DATA_PATH . '/config.php'); //To avoid access-rights problemsfile_put_contents(DATA_PATH . '/config.php', "<?php\n return " . var_export($config_array, true) . ";\n");+ if (function_exists('opcache_reset')) {+ opcache_reset();+ }+Minz_Configuration::register('system', DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php');FreshRSS_Context::$system_conf = Minz_Configuration::get('system');$ok = false;try {- $ok = checkDb();+ Minz_Session::_param('currentUser', $config_array['default_user']);+ $ok = initDb();+ Minz_Session::_param('currentUser');} catch (Exception $ex) {$_SESSION['bd_error'] = $ex->getMessage();$ok = false;diff --git a/cli/do-install.php b/cli/do-install.phpindex dea5d235e..fa6bac8c8 100755--- a/cli/do-install.php+++ b/cli/do-install.php@@ -82,7 +82,24 @@ if (file_put_contents(join_path(DATA_PATH, 'config.php'),fail('FreshRSS could not write configuration file!: ' . join_path(DATA_PATH, 'config.php'));}-if (!checkDb()) {+if (function_exists('opcache_reset')) {+ opcache_reset();+}++Minz_Configuration::register('system', DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php');+FreshRSS_Context::$system_conf = Minz_Configuration::get('system');++Minz_Session::_param('currentUser', $config['default_user']);++$ok = false;+try {+ $ok = initDb();+} catch (Exception $ex) {+ $_SESSION['bd_error'] = $ex->getMessage();+ $ok = false;+}++if (!$ok) {@unlink(join_path(DATA_PATH, 'config.php'));fail('FreshRSS database error: ' . (empty($_SESSION['bd_error']) ? 'Unknown error' : $_SESSION['bd_error']));}diff --git a/lib/Minz/ModelPdo.php b/lib/Minz/ModelPdo.phpindex 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.phpindex 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();