diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2019-02-22 13:54:20 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-22 13:54:20 +0300 |
commit | 2cc411862912b2e890c0d500b5ba1ce13a6013b6 (patch) | |
tree | 01c4eeb066ca058ae83bb2ea218b4c832ecc5f5c /lib | |
parent | 7c68e0eae7d378d73aa05361efbba835890c45c2 (diff) | |
parent | b4902369fbbbdddd80ef5043bfb3e9dbd9bf1732 (diff) |
Merge pull request #14066 from nextcloud/feature/noid/casted-system-values
Get typed system values
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 8 | ||||
-rw-r--r-- | lib/private/AllConfig.php | 36 | ||||
-rw-r--r-- | lib/private/Console/Application.php | 10 | ||||
-rw-r--r-- | lib/private/Route/Router.php | 2 | ||||
-rw-r--r-- | lib/private/Updater.php | 3 | ||||
-rw-r--r-- | lib/private/legacy/app.php | 2 | ||||
-rw-r--r-- | lib/public/IConfig.php | 30 |
7 files changed, 78 insertions, 13 deletions
diff --git a/lib/base.php b/lib/base.php index 90fa5496200..d5149fc0449 100644 --- a/lib/base.php +++ b/lib/base.php @@ -285,7 +285,7 @@ class OC { public static function checkMaintenanceMode() { // Allow ajax update script to execute without being stopped - if (\OC::$server->getSystemConfig()->getValue('maintenance', false) && OC::$SUBURI != '/core/ajax/update.php') { + if (((bool) \OC::$server->getSystemConfig()->getValue('maintenance', false)) && OC::$SUBURI != '/core/ajax/update.php') { // send http status 503 http_response_code(503); header('Retry-After: 120'); @@ -938,7 +938,7 @@ class OC { if (function_exists('opcache_reset')) { opcache_reset(); } - if (!$systemConfig->getValue('maintenance', false)) { + if (!((bool) $systemConfig->getValue('maintenance', false))) { self::printUpgradePage($systemConfig); exit(); } @@ -966,7 +966,7 @@ class OC { // Load minimum set of apps if (!\OCP\Util::needUpgrade() - && !$systemConfig->getValue('maintenance', false)) { + && !((bool) $systemConfig->getValue('maintenance', false))) { // For logged-in users: Load everything if(\OC::$server->getUserSession()->isLoggedIn()) { OC_App::loadApps(); @@ -979,7 +979,7 @@ class OC { if (!self::$CLI) { try { - if (!$systemConfig->getValue('maintenance', false) && !\OCP\Util::needUpgrade()) { + if (!((bool) $systemConfig->getValue('maintenance', false)) && !\OCP\Util::needUpgrade()) { OC_App::loadApps(array('filesystem', 'logging')); OC_App::loadApps(); } diff --git a/lib/private/AllConfig.php b/lib/private/AllConfig.php index 09520aae2a9..05ac1bad64b 100644 --- a/lib/private/AllConfig.php +++ b/lib/private/AllConfig.php @@ -126,6 +126,42 @@ class AllConfig implements \OCP\IConfig { } /** + * Looks up a boolean system wide defined value + * + * @param string $key the key of the value, under which it was saved + * @param mixed $default the default value to be returned if the value isn't set + * @return mixed the value or $default + * @since 16.0.0 + */ + public function getSystemValueBool(string $key, bool $default = false): bool { + return (bool) $this->getSystemValue($key, $default); + } + + /** + * Looks up an integer system wide defined value + * + * @param string $key the key of the value, under which it was saved + * @param mixed $default the default value to be returned if the value isn't set + * @return mixed the value or $default + * @since 16.0.0 + */ + public function getSystemValueInt(string $key, int $default = 0): int { + return (int) $this->getSystemValue($key, $default); + } + + /** + * Looks up a string system wide defined value + * + * @param string $key the key of the value, under which it was saved + * @param mixed $default the default value to be returned if the value isn't set + * @return mixed the value or $default + * @since 16.0.0 + */ + public function getSystemValueString(string $key, string $default = ''): string { + return (string) $this->getSystemValue($key, $default); + } + + /** * Looks up a system wide defined value and filters out sensitive data * * @param string $key the key of the value, under which it was saved diff --git a/lib/private/Console/Application.php b/lib/private/Console/Application.php index 0e30fa02b94..d7c047527f1 100644 --- a/lib/private/Console/Application.php +++ b/lib/private/Console/Application.php @@ -91,10 +91,10 @@ class Application { $inputDefinition = $application->getDefinition(); $inputDefinition->addOption( new InputOption( - 'no-warnings', - null, - InputOption::VALUE_NONE, - 'Skip global warnings, show command output only', + 'no-warnings', + null, + InputOption::VALUE_NONE, + 'Skip global warnings, show command output only', null ) ); @@ -119,7 +119,7 @@ class Application { if ($this->config->getSystemValue('installed', false)) { if (\OCP\Util::needUpgrade()) { throw new NeedsUpdateException(); - } elseif ($this->config->getSystemValue('maintenance', false)) { + } elseif ($this->config->getSystemValueBool('maintenance')) { $this->writeMaintenanceModeInfo($input, $output); } else { OC_App::loadApps(); diff --git a/lib/private/Route/Router.php b/lib/private/Route/Router.php index b44b3f7c2ce..1839b356424 100644 --- a/lib/private/Route/Router.php +++ b/lib/private/Route/Router.php @@ -260,7 +260,7 @@ class Router implements IRouter { $this->loadRoutes($app); } else if (substr($url, 0, 6) === '/core/' or substr($url, 0, 10) === '/settings/') { \OC::$REQUESTEDAPP = $url; - if (!\OC::$server->getConfig()->getSystemValue('maintenance', false) && !Util::needUpgrade()) { + if (!\OC::$server->getConfig()->getSystemValueBool('maintenance') && !Util::needUpgrade()) { \OC_App::loadApps(); } $this->loadRoutes('core'); diff --git a/lib/private/Updater.php b/lib/private/Updater.php index 4b4723be94f..313cfc82ffa 100644 --- a/lib/private/Updater.php +++ b/lib/private/Updater.php @@ -104,7 +104,7 @@ class Updater extends BasicEmitter { $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); $this->config->setSystemValue('loglevel', ILogger::DEBUG); - $wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); + $wasMaintenanceModeEnabled = $this->config->getSystemValueBool('maintenance'); if(!$wasMaintenanceModeEnabled) { $this->config->setSystemValue('maintenance', true); @@ -614,4 +614,3 @@ class Updater extends BasicEmitter { } } - diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index 4cab92eba64..9b4a83de349 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -106,7 +106,7 @@ class OC_App { * if $types is set to non-empty array, only apps of those types will be loaded */ public static function loadApps(array $types = []): bool { - if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { + if ((bool) \OC::$server->getSystemConfig()->getValue('maintenance', false)) { return false; } // Load the enabled apps here diff --git a/lib/public/IConfig.php b/lib/public/IConfig.php index e4cd158f872..878c0acf0c3 100644 --- a/lib/public/IConfig.php +++ b/lib/public/IConfig.php @@ -75,6 +75,36 @@ interface IConfig { public function getSystemValue($key, $default = ''); /** + * Looks up a boolean system wide defined value + * + * @param string $key the key of the value, under which it was saved + * @param bool $default the default value to be returned if the value isn't set + * @return bool the value or $default + * @since 16.0.0 + */ + public function getSystemValueBool(string $key, bool $default = false): bool; + + /** + * Looks up an integer system wide defined value + * + * @param string $key the key of the value, under which it was saved + * @param int $default the default value to be returned if the value isn't set + * @return int the value or $default + * @since 16.0.0 + */ + public function getSystemValueInt(string $key, int $default = 0): int; + + /** + * Looks up a string system wide defined value + * + * @param string $key the key of the value, under which it was saved + * @param string $default the default value to be returned if the value isn't set + * @return string the value or $default + * @since 16.0.0 + */ + public function getSystemValueString(string $key, string $default = ''): string; + + /** * Looks up a system wide defined value and filters out sensitive data * * @param string $key the key of the value, under which it was saved |