Skip to content

Commit

Permalink
Refactor OC\Server::getSystemConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
summersab committed Aug 29, 2023
1 parent 613cd16 commit 404b387
Show file tree
Hide file tree
Showing 23 changed files with 62 additions and 35 deletions.
3 changes: 2 additions & 1 deletion core/ajax/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use OC\Repair\Events\RepairStartEvent;
use OC\Repair\Events\RepairStepEvent;
use OC\Repair\Events\RepairWarningEvent;
use OC\SystemConfig;
use OCP\L10N\IFactory;

if (!str_contains(@ini_get('disable_functions'), 'set_time_limit')) {
Expand Down Expand Up @@ -100,7 +101,7 @@ public function handleRepairFeedback(Event $event): void {
}

if (\OCP\Util::needUpgrade()) {
$config = \OC::$server->getSystemConfig();
$config = \OC::$server->get(SystemConfig::class);
if ($config->getValue('upgrade.disable-web', false)) {
$eventSource->send('failure', $l->t('Please use the command line updater because updating via browser is disabled in your config.php.'));
$eventSource->close();
Expand Down
14 changes: 8 additions & 6 deletions core/register_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

use OC\SystemConfig;
use Psr\Log\LoggerInterface;

$application->add(new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand());
$application->add(new OC\Core\Command\Status(\OC::$server->get(\OCP\IConfig::class), \OC::$server->get(\OCP\Defaults::class)));
$application->add(new OC\Core\Command\Check(\OC::$server->getSystemConfig()));
$application->add(new OC\Core\Command\Check(\OC::$server->get(SystemConfig::class)));
$application->add(new OC\Core\Command\L10n\CreateJs());
$application->add(new \OC\Core\Command\Integrity\SignApp(
\OC::$server->getIntegrityCodeChecker(),
Expand Down Expand Up @@ -98,15 +100,15 @@
$application->add(new OC\Core\Command\Config\App\GetConfig(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Config\App\SetConfig(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Config\Import(\OC::$server->getConfig()));
$application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig()));
$application->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->getSystemConfig()));
$application->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->getSystemConfig()));
$application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig()));
$application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->get(SystemConfig::class), \OC::$server->getAppConfig()));
$application->add(new OC\Core\Command\Config\System\DeleteConfig(\OC::$server->get(SystemConfig::class)));
$application->add(new OC\Core\Command\Config\System\GetConfig(\OC::$server->get(SystemConfig::class)));
$application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->get(SystemConfig::class)));

$application->add(\OC::$server->get(OC\Core\Command\Info\File::class));
$application->add(\OC::$server->get(OC\Core\Command\Info\Space::class));

$application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig())));
$application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->get(SystemConfig::class))));
$application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->get(LoggerInterface::class)));
$application->add(new OC\Core\Command\Db\ConvertFilecacheBigInt(\OC::$server->get(\OC\DB\Connection::class)));
$application->add(\OCP\Server::get(\OC\Core\Command\Db\AddMissingColumns::class));
Expand Down
4 changes: 3 additions & 1 deletion cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@
*/
require_once __DIR__ . '/lib/versioncheck.php';

use OC\SystemConfig;

try {
require_once __DIR__ . '/lib/base.php';

if (\OCP\Util::needUpgrade()) {
\OC::$server->getLogger()->debug('Update required, skipping cron', ['app' => 'cron']);
exit;
}
if ((bool) \OC::$server->getSystemConfig()->getValue('maintenance', false)) {
if ((bool) \OC::$server->get(SystemConfig::class)->getValue('maintenance', false)) {
\OC::$server->getLogger()->debug('We are in maintenance mode, skipping cron', ['app' => 'cron']);
exit;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

use OC\MemoryInfo;
use OC\NeedsUpdateException;
use OC\SystemConfig;
use OC_App;
use OCP\App\IAppManager;
use OCP\Console\ConsoleEvent;
Expand Down Expand Up @@ -157,7 +158,7 @@ public function loadCommands(
}

if ($input->getFirstArgument() !== 'check') {
$errors = \OC_Util::checkServer(\OC::$server->getSystemConfig());
$errors = \OC_Util::checkServer(\OC::$server->get(SystemConfig::class));
if (!empty($errors)) {
foreach ($errors as $error) {
$output->writeln((string)$error['error']);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/DB/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function __construct(
$this->adapter = new $params['adapter']($this);
$this->tablePrefix = $params['tablePrefix'];

$this->systemConfig = \OC::$server->getSystemConfig();
$this->systemConfig = \OC::$server->get(SystemConfig::class);
$this->logger = \OC::$server->get(LoggerInterface::class);

/** @var \OCP\Profiler\IProfiler */
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchQuery;
use OC\Files\Storage\Wrapper\Encryption;
use OC\SystemConfig;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\CacheEntryInsertedEvent;
Expand Down Expand Up @@ -131,7 +132,7 @@ public function __construct(IStorage $storage) {
protected function getQueryBuilder() {
return new CacheQueryBuilder(
$this->connection,
\OC::$server->getSystemConfig(),
\OC::$server->get(SystemConfig::class),
\OC::$server->get(LoggerInterface::class)
);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Files/Storage/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
use OC\Files\Filesystem;
use OC\Files\Storage\Wrapper\Jail;
use OC\Files\Storage\Wrapper\Wrapper;
use OC\SystemConfig;
use OCP\Files\EmptyFileNameException;
use OCP\Files\FileNameTooLongException;
use OCP\Files\ForbiddenException;
Expand Down Expand Up @@ -381,7 +382,7 @@ public function getPropagator($storage = null) {
$storage = $this;
}
if (!isset($storage->propagator)) {
$config = \OC::$server->getSystemConfig();
$config = \OC::$server->get(SystemConfig::class);
$storage->propagator = new Propagator($storage, \OC::$server->getDatabaseConnection(), ['appdata_' . $config->getValue('instanceid')]);
}
return $storage->propagator;
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use OCP\Support\CrashReport\IRegistry;
use OC\AppFramework\Bootstrap\Coordinator;
use OC\Log\ExceptionSerializer;
use OC\SystemConfig;
use Throwable;
use function array_merge;
use function strtr;
Expand Down Expand Up @@ -83,7 +84,7 @@ public function __construct(
) {
// FIXME: Add this for backwards compatibility, should be fixed at some point probably
if ($config === null) {
$config = \OC::$server->getSystemConfig();
$config = \OC::$server->get(SystemConfig::class);
}

$this->config = $config;
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Log/Rotate.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
namespace OC\Log;

use OC\SystemConfig;
use OCP\Log\RotationTrait;

/**
Expand All @@ -36,7 +37,7 @@ class Rotate extends \OCP\BackgroundJob\Job {
use RotationTrait;

public function run($dummy) {
$systemConfig = \OC::$server->getSystemConfig();
$systemConfig = \OC::$server->get(SystemConfig::class);
$this->filePath = $systemConfig->getValue('logfile', $systemConfig->getValue('datadirectory', \OC::$SERVERROOT . '/data') . '/nextcloud.log');

$this->maxSize = \OC::$server->getConfig()->getSystemValueInt('log_rotate_size', 100 * 1024 * 1024);
Expand Down
5 changes: 3 additions & 2 deletions lib/private/Memcache/Memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*/
namespace OC\Memcache;

use OC\SystemConfig;
use OCP\HintException;
use OCP\IMemcache;

Expand Down Expand Up @@ -84,9 +85,9 @@ public function __construct($prefix = '') {
throw new HintException("Expected 'memcached_options' config to be an array, got $options");
}

$servers = \OC::$server->getSystemConfig()->getValue('memcached_servers');
$servers = \OC::$server->get(SystemConfig::class)->getValue('memcached_servers');
if (!$servers) {
$server = \OC::$server->getSystemConfig()->getValue('memcached_server');
$server = \OC::$server->get(SystemConfig::class)->getValue('memcached_server');
if ($server) {
$servers = [$server];
} else {
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
use OC\TextProcessing\RemoveOldTasksBackgroundJob;
use OC\Log\Rotate;
use OC\Preview\BackgroundCleanupJob;
use OC\SystemConfig;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Defaults;
use OCP\IGroup;
Expand Down Expand Up @@ -496,7 +497,7 @@ private static function findWebRoot(SystemConfig $config): string {
* @throws \OCP\AppFramework\QueryException
*/
public static function updateHtaccess() {
$config = \OC::$server->getSystemConfig();
$config = \OC::$server->get(SystemConfig::class);

try {
$webRoot = self::findWebRoot($config);
Expand Down
5 changes: 3 additions & 2 deletions lib/private/TemplateLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

use bantu\IniGetWrapper\IniGetWrapper;
use OC\Search\SearchQuery;
use OC\SystemConfig;
use OC\Template\CSSResourceLocator;
use OC\Template\JSConfigHelper;
use OC\Template\JSResourceLocator;
Expand Down Expand Up @@ -207,7 +208,7 @@ public function __construct($renderAs, $appId = '') {
$this->assign('language', $lang);
$this->assign('locale', $locale);

if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
if (empty(self::$versionHash)) {
$v = \OC_App::getAppVersions();
$v['core'] = implode('.', \OCP\Util::getVersion());
Expand Down Expand Up @@ -258,7 +259,7 @@ public function __construct($renderAs, $appId = '') {

// Do not initialise scss appdata until we have a fully installed instance
// Do not load scss for update, errors, installation or login page
if (\OC::$server->getSystemConfig()->getValue('installed', false)
if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)
&& !\OCP\Util::needUpgrade()
&& $pathInfo !== ''
&& !preg_match('/^\/login/', $pathInfo)
Expand Down
5 changes: 3 additions & 2 deletions lib/private/legacy/OC_App.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
use OC\Installer;
use OC\Repair;
use OC\Repair\Events\RepairErrorEvent;
use OC\SystemConfig;
use Psr\Container\ContainerExceptionInterface;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -119,7 +120,7 @@ public static function isAppLoaded(string $app): bool {
* 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('installed', false)) {
if (!\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
// This should be done before calling this method so that appmanager can be used
return false;
}
Expand Down Expand Up @@ -216,7 +217,7 @@ public static function setAppTypes(string $app) {
* @return string[]
*/
public static function getEnabledApps(bool $forceRefresh = false, bool $all = false): array {
if (!\OC::$server->getSystemConfig()->getValue('installed', false)) {
if (!\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
return [];
}
// in incognito mode or when logged out, $user will be false,
Expand Down
3 changes: 2 additions & 1 deletion lib/private/legacy/OC_Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
*/
use bantu\IniGetWrapper\IniGetWrapper;
use OC\Files\Filesystem;
use OC\SystemConfig;
use OCP\Files\Mount\IMountPoint;
use OCP\ICacheFactory;
use OCP\IBinaryFinder;
Expand Down Expand Up @@ -484,7 +485,7 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin

// return storage info without adding mount points
if (self::$quotaIncludeExternalStorage === null) {
self::$quotaIncludeExternalStorage = \OC::$server->getSystemConfig()->getValue('quota_include_external_storage', false);
self::$quotaIncludeExternalStorage = \OC::$server->get(SystemConfig::class)->getValue('quota_include_external_storage', false);
}

$view = Filesystem::getView();
Expand Down
4 changes: 3 additions & 1 deletion lib/private/legacy/OC_Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

use OC\SystemConfig;
use OC\TemplateLayout;
use OCP\AppFramework\Http\TemplateResponse;

Expand Down Expand Up @@ -285,7 +287,7 @@ public static function printExceptionErrorPage($exception, $statusCode = 503) {
$content->assign('file', $exception->getFile());
$content->assign('line', $exception->getLine());
$content->assign('exception', $exception);
$content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false));
$content->assign('debugMode', \OC::$server->get(SystemConfig::class)->getValue('debug', false));
$content->assign('remoteAddr', $request->getRemoteAddress());
$content->assign('requestID', $request->getId());
$content->printPage();
Expand Down
5 changes: 3 additions & 2 deletions lib/private/legacy/OC_User.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
*
*/

use OC\SystemConfig;
use OC\User\LoginException;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ILogger;
Expand Down Expand Up @@ -126,7 +127,7 @@ public static function clearBackends() {
*/
public static function setupBackends() {
OC_App::loadApps(['prelogin']);
$backends = \OC::$server->getSystemConfig()->getValue('user_backends', []);
$backends = \OC::$server->get(SystemConfig::class)->getValue('user_backends', []);
if (isset($backends['default']) && !$backends['default']) {
// clear default backends
self::clearBackends();
Expand Down Expand Up @@ -377,7 +378,7 @@ public static function getHome($uid) {
if ($user) {
return $user->getHome();
} else {
return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid;
return \OC::$server->get(SystemConfig::class)->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid;
}
}

Expand Down
7 changes: 4 additions & 3 deletions lib/private/legacy/OC_Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@

use bantu\IniGetWrapper\IniGetWrapper;
use OC\Files\SetupManager;
use OC\SystemConfig;
use OCP\Files\Template\ITemplateManager;
use OCP\IConfig;
use OCP\IGroupManager;
Expand Down Expand Up @@ -842,11 +843,11 @@ public static function redirectToDefaultPage() {
* @return string
*/
public static function getInstanceId() {
$id = \OC::$server->getSystemConfig()->getValue('instanceid', null);
$id = \OC::$server->get(SystemConfig::class)->getValue('instanceid', null);
if (is_null($id)) {
// We need to guarantee at least one letter in instanceid so it can be used as the session_name
$id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS);
\OC::$server->getSystemConfig()->setValue('instanceid', $id);
\OC::$server->get(SystemConfig::class)->setValue('instanceid', $id);
}
return $id;
}
Expand Down Expand Up @@ -1053,7 +1054,7 @@ public static function runningOnMac() {
* @return string the theme
*/
public static function getTheme() {
$theme = \OC::$server->getSystemConfig()->getValue("theme", '');
$theme = \OC::$server->get(SystemConfig::class)->getValue("theme", '');

if ($theme === '') {
if (is_dir(OC::$SERVERROOT . '/themes/default')) {
Expand Down
3 changes: 2 additions & 1 deletion lib/public/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

use OC\AppScriptDependency;
use OC\AppScriptSort;
use OC\SystemConfig;
use bantu\IniGetWrapper\IniGetWrapper;
use Psr\Container\ContainerExceptionInterface;

Expand Down Expand Up @@ -563,7 +564,7 @@ public static function isDefaultExpireDateEnforced() {
*/
public static function needUpgrade() {
if (!isset(self::$needUpgradeCache)) {
self::$needUpgradeCache = \OC_Util::needUpgrade(\OC::$server->getSystemConfig());
self::$needUpgradeCache = \OC_Util::needUpgrade(\OC::$server->get(SystemConfig::class));
}
return self::$needUpgradeCache;
}
Expand Down
4 changes: 3 additions & 1 deletion ocs/v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
require_once __DIR__ . '/../lib/versioncheck.php';
require_once __DIR__ . '/../lib/base.php';

use OC\SystemConfig;

if (\OCP\Util::needUpgrade()
|| \OC::$server->getConfig()->getSystemValueBool('maintenance')) {
// since the behavior of apps or remotes are unpredictable during
Expand Down Expand Up @@ -83,7 +85,7 @@
$format = \OC::$server->getRequest()->getParam('format', 'xml');
$txt = 'Internal Server Error'."\n";
try {
if (\OC::$server->getSystemConfig()->getValue('debug', false)) {
if (\OC::$server->get(SystemConfig::class)->getValue('debug', false)) {
$txt .= $e->getMessage();
}
} catch (\Throwable $e) {
Expand Down
4 changes: 3 additions & 1 deletion status.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@
*/
require_once __DIR__ . '/lib/versioncheck.php';

use OC\SystemConfig;

try {
require_once __DIR__ . '/lib/base.php';

$systemConfig = \OC::$server->getSystemConfig();
$systemConfig = \OC::$server->get(SystemConfig::class);

$installed = (bool) $systemConfig->getValue('installed', false);
$maintenance = (bool) $systemConfig->getValue('maintenance', false);
Expand Down
Loading

0 comments on commit 404b387

Please sign in to comment.