-
-
Notifications
You must be signed in to change notification settings - Fork 784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix database autocreate at install #2635
Conversation
Several bugs prevented the auto-creation of the database in Web and CLI installs. Fix YunoHost-Apps/freshrss_ynh#84 (comment)
Tested by @plopoyop |
@@ -85,14 +85,21 @@ function checkDb() { | |||
$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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why you need to re-set the $db in conf, but I would avoid this side effect. But maybe we can't do differently due to the actual architecture?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly: FreshRSS_Context::$system_conf->db['key'] = 'value';
does not work due to the fact that Minz introduces a barrier with __get()
.
The error message is in the comment: Indirect modification of overloaded property
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I meant is, why checkDb
changes the system conf? For me, the method should not touch the conf unless to read it.
… and writing this, I realize that maybe it's just that checkDb
is badly named, perhaps something like initDb
would be more self-explanatory?
Ok, forget about it ^^'
Concerning the "todo", I would add it in the lib/Minz/Configuration.php
, where it has more sense (otherwise, we would add it each time we do this). I also cherish the idea of rewriting the configuration system for something simpler… one day :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed for changing the name. And yes for changing the configuration, as we are not really using its advantages (setters and getters) but we pay its drawbacks (layers that make the syntax more complex and error prone).
The comment was more to explain the strange syntax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name changed 41179be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To complete my comment, I would appreciate a more detailed commit message to explain the changes (at least what bugs are you patching?) I'm pretty ok with the PR, but in the same time I don't feel like my review is really useful since I'm just guessing the problem(s) :(
@@ -102,7 +102,9 @@ public function addFeedObject($feed) { | |||
'httpAuth' => $feed->httpAuth(), | |||
'attributes' => $feed->attributes(), | |||
); | |||
if ($feed->mute() || $feed->ttl() != FreshRSS_Context::$user_conf->ttl_default) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FreshRSS_Context::$user_conf
is not available when creating a new user
@@ -132,7 +132,7 @@ function saveStep2() { | |||
$config_array = [ | |||
'salt' => generateSalt(), | |||
'base_url' => $base_url, | |||
'default_user' => 'admin', | |||
'default_user' => '_', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that we can touch e.g. an SQLite database in the ./data/users/_/
folder, which is the only one we have so early in the install process
@@ -154,12 +154,18 @@ function saveStep2() { | |||
@unlink(DATA_PATH . '/config.php'); //To avoid access-rights problems | |||
file_put_contents(DATA_PATH . '/config.php', "<?php\n return " . var_export($config_array, true) . ";\n"); | |||
|
|||
if (function_exists('opcache_reset')) { | |||
opcache_reset(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should always clear opcache before reading a dynamically generated PHP file.
Minz_Configuration::register('system', DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php'); | ||
FreshRSS_Context::$system_conf = Minz_Configuration::get('system'); | ||
|
||
$ok = false; | ||
try { | ||
Minz_Session::_param('currentUser', $config_array['default_user']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is before we actually have the name of a real user, so use default one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit upset with this one: we need the session variable really deep in the code and it's absolutely not intuitive. I know it's not the fault of this PR at all and we'll not change it quite soon… but I'd love to keep track somehow of this kind of technical debt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, maybe by using only the Context object, and if so it would not be a big change
} | ||
|
||
Minz_Configuration::register('system', DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php'); | ||
FreshRSS_Context::$system_conf = Minz_Configuration::get('system'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The configuration was not loaded
@@ -28,6 +28,9 @@ public function __construct($currentUser = null, $currentPdo = null) { | |||
if ($currentUser === null) { | |||
$currentUser = Minz_Session::param('currentUser'); | |||
} | |||
if ($currentUser == '') { | |||
throw new Minz_PDOConnectionException('Current user must not be empty!', '', Minz_Exception::ERROR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another barrier to prevent logic from running without a proper user. The other bugs fixed in the PR allowed coming here with a blank user
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks cli (cf. #2644 ) Removing this two lines is enough to make cli works again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@X-dark Thanks for the heads up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by #2646
Minz_ModelPdo::$usesSharedPdo = false; | ||
$databaseDAO = FreshRSS_Factory::createDatabaseDAO(); | ||
$databaseDAO->create(); | ||
if ($db['type'] !== 'sqlite') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no global database to create for SQLite
@marienfressinaud I have added some comments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comments! Even if I made some comments, it's generic and out of the scope.
Minz_Configuration::register('system', DATA_PATH . '/config.php', FRESHRSS_PATH . '/config.default.php'); | ||
FreshRSS_Context::$system_conf = Minz_Configuration::get('system'); | ||
|
||
$ok = false; | ||
try { | ||
Minz_Session::_param('currentUser', $config_array['default_user']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit upset with this one: we need the session variable really deep in the code and it's absolutely not intuitive. I know it's not the fault of this PR at all and we'll not change it quite soon… but I'd love to keep track somehow of this kind of technical debt.
@@ -85,14 +85,21 @@ function checkDb() { | |||
$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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I meant is, why checkDb
changes the system conf? For me, the method should not touch the conf unless to read it.
… and writing this, I realize that maybe it's just that checkDb
is badly named, perhaps something like initDb
would be more self-explanatory?
Ok, forget about it ^^'
Concerning the "todo", I would add it in the lib/Minz/Configuration.php
, where it has more sense (otherwise, we would add it each time we do this). I also cherish the idea of rewriting the configuration system for something simpler… one day :)
One forgotten condition. Related to FreshRSS#2646 and FreshRSS#2635
* Fix database autocreate at install Several bugs prevented the auto-creation of the database in Web and CLI installs. Fix YunoHost-Apps/freshrss_ynh#84 (comment) * initDb FreshRSS#2635 (comment)
One forgotten condition. Related to FreshRSS#2646 and FreshRSS#2635
Several bugs prevented the auto-creation of the database in Web and CLI installs.
Fix YunoHost-Apps/freshrss_ynh#84 (comment)