diff options
| author | 2021-01-02 21:20:19 +0100 | |
|---|---|---|
| committer | 2021-01-02 21:20:19 +0100 | |
| commit | 9c6682e7edf8cbad828088cbeeef66c7ecefdd9a (patch) | |
| tree | c8c8a6ba34d49d22497a14ddaf18ae97d8cd5bb1 /cli | |
| parent | 7bc2cc5825547f5b5cf15005fda937e06065b45d (diff) | |
Avoid manual initialisations of system or user configuration (#3070)
* Avoid manual intialisations of system or user configuration
More consistent use of Context
* Simplify FreshRSS_Context::initUser
* Remove a few manual get_user_configuration
* A bit of debugging
* Fix context user init
* Fix install
* Fix concurrency
Concurrent requests could lead to bad race condition
* Fix actualize cron
Fix case when system i initialised several times
Diffstat (limited to 'cli')
| -rw-r--r-- | cli/_cli.php | 9 | ||||
| -rwxr-xr-x | cli/do-install.php | 3 | ||||
| -rwxr-xr-x | cli/reconfigure.php | 19 | ||||
| -rwxr-xr-x | cli/user-info.php | 9 |
4 files changed, 17 insertions, 23 deletions
diff --git a/cli/_cli.php b/cli/_cli.php index 68a0f8731..dc7ee9d64 100644 --- a/cli/_cli.php +++ b/cli/_cli.php @@ -11,10 +11,7 @@ require(LIB_PATH . '/lib_rss.php'); //Includes class autoloader require(LIB_PATH . '/lib_install.php'); Minz_Session::init('FreshRSS', true); -Minz_Configuration::register('system', - DATA_PATH . '/config.php', - FRESHRSS_PATH . '/config.default.php'); -FreshRSS_Context::$system_conf = Minz_Configuration::get('system'); +FreshRSS_Context::initSystem(); Minz_Translate::init('en'); FreshRSS_Context::$isCli = true; @@ -34,11 +31,9 @@ function cliInitUser($username) { fail('FreshRSS error: user not found: ' . $username . "\n"); } - FreshRSS_Context::$user_conf = get_user_configuration($username); - if (FreshRSS_Context::$user_conf == null) { + if (!FreshRSS_Context::initUser($username)) { fail('FreshRSS error: invalid configuration for user: ' . $username . "\n"); } - Minz_Session::_param('currentUser', $username); return $username; } diff --git a/cli/do-install.php b/cli/do-install.php index 3fa9cd63e..fd51003ab 100755 --- a/cli/do-install.php +++ b/cli/do-install.php @@ -86,8 +86,7 @@ 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'); +FreshRSS_Context::initSystem(); Minz_Session::_param('currentUser', '_'); //Default user diff --git a/cli/reconfigure.php b/cli/reconfigure.php index 45e913d76..7495fc367 100755 --- a/cli/reconfigure.php +++ b/cli/reconfigure.php @@ -37,14 +37,13 @@ if (!validateOptions($argv, array_merge($params, $dBparams))) { fwrite(STDERR, 'Reconfiguring FreshRSS…' . "\n"); -$config = Minz_Configuration::get('system'); foreach ($params as $param) { $param = rtrim($param, ':'); if (isset($options[$param])) { - $config->$param = $options[$param] === false ? true : $options[$param]; + FreshRSS_Context::$system_conf->$param = $options[$param] === false ? true : $options[$param]; } } -$db = $config->db; +$db = FreshRSS_Context::$system_conf->db; foreach ($dBparams as $dBparam) { $dBparam = rtrim($dBparam, ':'); if (isset($options[$dBparam])) { @@ -52,17 +51,19 @@ foreach ($dBparams as $dBparam) { $db[$param] = $options[$dBparam]; } } -$config->db = $db; +FreshRSS_Context::$system_conf->db = $db; -if (!FreshRSS_user_Controller::checkUsername($config->default_user)) { - fail('FreshRSS invalid default username (must be ASCII alphanumeric): ' . $config->default_user); +if (!FreshRSS_user_Controller::checkUsername(FreshRSS_Context::$system_conf->default_user)) { + fail('FreshRSS invalid default username (must be ASCII alphanumeric): ' . + FreshRSS_Context::$system_conf->default_user); } -if (isset($config->auth_type) && !in_array($config->auth_type, array('form', 'http_auth', 'none'))) { +if (isset(FreshRSS_Context::$system_conf->auth_type) && + !in_array(FreshRSS_Context::$system_conf->auth_type, array('form', 'http_auth', 'none'))) { fail('FreshRSS invalid authentication method (auth_type must be one of { form, http_auth, none }: ' - . $config->auth_type); + . FreshRSS_Context::$system_conf->auth_type); } -$config->save(); +FreshRSS_Context::$system_conf->save(); done(); diff --git a/cli/user-info.php b/cli/user-info.php index 95381ce33..582d10431 100755 --- a/cli/user-info.php +++ b/cli/user-info.php @@ -55,7 +55,6 @@ if (array_key_exists('header', $options)) { foreach ($users as $username) { $username = cliInitUser($username); - $userConfiguration = get_user_configuration($username); $catDAO = FreshRSS_Factory::createCategoryDao($username); $feedDAO = FreshRSS_Factory::createFeedDao($username); $entryDAO = FreshRSS_Factory::createEntryDao($username); @@ -68,8 +67,8 @@ foreach ($users as $username) { $data = array( 'default' => $username === FreshRSS_Context::$system_conf->default_user ? '*' : '', 'user' => $username, - 'admin' => $userConfiguration->is_admin ? '*' : '', - 'enabled' => $userConfiguration->enabled ? '*' : '', + 'admin' => FreshRSS_Context::$user_conf->is_admin ? '*' : '', + 'enabled' => FreshRSS_Context::$user_conf->enabled ? '*' : '', 'last_user_activity' => FreshRSS_UserDAO::mtime($username), 'database_size' => $databaseDAO->size(), 'categories' => (int) $catDAO->count(), @@ -78,8 +77,8 @@ foreach ($users as $username) { 'unreads' => (int) $nbEntries['unread'], 'favourites' => (int) $nbFavorites['all'], 'tags' => (int) $tagDAO->count(), - 'lang' => $userConfiguration->language, - 'mail_login' => $userConfiguration->mail_login, + 'lang' => FreshRSS_Context::$user_conf->language, + 'mail_login' => FreshRSS_Context::$user_conf->mail_login, ); if (isset($options['h'])) { //Human format $data['last_user_activity'] = date('c', $data['last_user_activity']); |
