Skip to content
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

Merged
merged 2 commits into from
Nov 6, 2019
Merged

Conversation

Alkarex
Copy link
Member

@Alkarex Alkarex commented Nov 5, 2019

Several bugs prevented the auto-creation of the database in Web and CLI installs.
Fix YunoHost-Apps/freshrss_ynh#84 (comment)

Several bugs prevented the auto-creation of the database in Web and CLI
installs.
Fix
YunoHost-Apps/freshrss_ynh#84 (comment)
@Alkarex
Copy link
Member Author

Alkarex commented Nov 5, 2019

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"
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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 :)

Copy link
Member Author

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name changed 41179be

Copy link
Member

@marienfressinaud marienfressinaud left a 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) {
Copy link
Member Author

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' => '_',
Copy link
Member Author

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();
Copy link
Member Author

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']);
Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member Author

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');
Copy link
Member Author

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);
Copy link
Member Author

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

Copy link

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.

Copy link
Member Author

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

Copy link
Member Author

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') {
Copy link
Member Author

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

@Alkarex
Copy link
Member Author

Alkarex commented Nov 6, 2019

@marienfressinaud I have added some comments

Copy link
Member

@marienfressinaud marienfressinaud left a 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']);
Copy link
Member

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"
Copy link
Member

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 :)

@Alkarex Alkarex merged commit 2203015 into FreshRSS:dev Nov 6, 2019
@Alkarex Alkarex deleted the fix_install branch November 6, 2019 14:16
@Alkarex Alkarex mentioned this pull request Nov 6, 2019
Alkarex added a commit to Alkarex/FreshRSS that referenced this pull request Nov 8, 2019
One forgotten condition. Related to
FreshRSS#2646 and
FreshRSS#2635
Alkarex added a commit that referenced this pull request Nov 9, 2019
One forgotten condition. Related to
#2646 and
#2635
javerous pushed a commit to javerous/FreshRSS that referenced this pull request Jan 20, 2020
* 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)
javerous pushed a commit to javerous/FreshRSS that referenced this pull request Jan 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants