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

Use typed version of IConfig::getSystemValue as much as possible #37596

Merged
merged 3 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ private static function performSameSiteCookieProtection(\OCP\IConfig $config): v
self::sendSameSiteCookies();
// Debug mode gets access to the resources without strict cookie
// due to the fact that the SabreDAV browser also lives there.
if (!$config->getSystemValue('debug', false)) {
if (!$config->getSystemValueBool('debug', false)) {
http_response_code(\OCP\AppFramework\Http::STATUS_PRECONDITION_FAILED);
header('Content-Type: application/json');
echo json_encode(['error' => 'Strict Cookie has not been found in request']);
Expand Down Expand Up @@ -674,7 +674,7 @@ public static function init(): void {
\OCP\Server::get(\Psr\Log\LoggerInterface::class),
);
$exceptionHandler = [$errorHandler, 'onException'];
if ($config->getSystemValue('debug', false)) {
if ($config->getSystemValueBool('debug', false)) {
set_error_handler([$errorHandler, 'onAll'], E_ALL);
if (\OC::$CLI) {
$exceptionHandler = ['OC_Template', 'printExceptionErrorPage'];
Expand Down Expand Up @@ -735,7 +735,7 @@ public static function init(): void {
echo('Writing to database failed');
}
exit(1);
} elseif (self::$CLI && $config->getSystemValue('installed', false)) {
} elseif (self::$CLI && $config->getSystemValueBool('installed', false)) {
$config->deleteAppValue('core', 'cronErrors');
}
}
Expand Down Expand Up @@ -805,7 +805,7 @@ public static function init(): void {
*/
if (!OC::$CLI
&& !Server::get(\OC\Security\TrustedDomainHelper::class)->isTrustedDomain($host)
&& $config->getSystemValue('installed', false)
&& $config->getSystemValueBool('installed', false)
) {
// Allow access to CSS resources
$isScssRequest = false;
Expand Down
14 changes: 7 additions & 7 deletions lib/private/App/AppStore/Fetcher/Fetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ abstract class Fetcher {
protected $fileName;
/** @var string */
protected $endpointName;
/** @var string */
protected $version;
/** @var string */
protected $channel;
/** @var ?string */
protected $version = null;
/** @var ?string */
protected $channel = null;

public function __construct(Factory $appDataFactory,
IClientService $clientService,
Expand Down Expand Up @@ -149,7 +149,7 @@ protected function fetch($ETag, $content) {
*/
public function get($allowUnstable = false) {
$appstoreenabled = $this->config->getSystemValueBool('appstoreenabled', true);
$internetavailable = $this->config->getSystemValue('has_internet_connection', true);
$internetavailable = $this->config->getSystemValueBool('has_internet_connection', true);

if (!$appstoreenabled || !$internetavailable) {
return [];
Expand Down Expand Up @@ -218,7 +218,7 @@ public function get($allowUnstable = false) {
*/
protected function getVersion() {
if ($this->version === null) {
$this->version = $this->config->getSystemValue('version', '0.0.0');
$this->version = $this->config->getSystemValueString('version', '0.0.0');
}
return $this->version;
}
Expand Down Expand Up @@ -251,6 +251,6 @@ public function setChannel(string $channel) {
}

protected function getEndpoint(): string {
return $this->config->getSystemValue('appstoreurl', 'https://apps.nextcloud.com/api/v1') . '/' . $this->endpointName;
return $this->config->getSystemValueString('appstoreurl', 'https://apps.nextcloud.com/api/v1') . '/' . $this->endpointName;
}
}
2 changes: 1 addition & 1 deletion lib/private/App/Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function getOcVersion(): string {
}

public function getDatabase(): string {
$dbType = $this->config->getSystemValue('dbtype', 'sqlite');
$dbType = $this->config->getSystemValueString('dbtype', 'sqlite');
if ($dbType === 'sqlite3') {
$dbType = 'sqlite';
}
Expand Down
14 changes: 7 additions & 7 deletions lib/private/AppFramework/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ public function getRemoteAddress(): string {
* @return bool
*/
private function isOverwriteCondition(string $type = ''): bool {
$regex = '/' . $this->config->getSystemValue('overwritecondaddr', '') . '/';
$regex = '/' . $this->config->getSystemValueString('overwritecondaddr', '') . '/';
$remoteAddr = isset($this->server['REMOTE_ADDR']) ? $this->server['REMOTE_ADDR'] : '';
return $regex === '//' || preg_match($regex, $remoteAddr) === 1
|| $type !== 'protocol';
Expand All @@ -636,9 +636,9 @@ private function isOverwriteCondition(string $type = ''): bool {
* @return string Server protocol (http or https)
*/
public function getServerProtocol(): string {
if ($this->config->getSystemValue('overwriteprotocol') !== ''
if ($this->config->getSystemValueString('overwriteprotocol') !== ''
&& $this->isOverwriteCondition('protocol')) {
return $this->config->getSystemValue('overwriteprotocol');
return $this->config->getSystemValueString('overwriteprotocol');
}

if ($this->fromTrustedProxy() && isset($this->server['HTTP_X_FORWARDED_PROTO'])) {
Expand Down Expand Up @@ -696,7 +696,7 @@ public function getHttpProtocol(): string {
*/
public function getRequestUri(): string {
$uri = isset($this->server['REQUEST_URI']) ? $this->server['REQUEST_URI'] : '';
if ($this->config->getSystemValue('overwritewebroot') !== '' && $this->isOverwriteCondition()) {
if ($this->config->getSystemValueString('overwritewebroot') !== '' && $this->isOverwriteCondition()) {
$uri = $this->getScriptName() . substr($uri, \strlen($this->server['SCRIPT_NAME']));
}
return $uri;
Expand Down Expand Up @@ -764,7 +764,7 @@ public function getPathInfo() {
*/
public function getScriptName(): string {
$name = $this->server['SCRIPT_NAME'];
$overwriteWebRoot = $this->config->getSystemValue('overwritewebroot');
$overwriteWebRoot = $this->config->getSystemValueString('overwritewebroot');
if ($overwriteWebRoot !== '' && $this->isOverwriteCondition()) {
// FIXME: This code is untestable due to __DIR__, also that hardcoded path is really dangerous
$serverRoot = str_replace('\\', '/', substr(__DIR__, 0, -\strlen('lib/private/appframework/http/')));
Expand Down Expand Up @@ -859,8 +859,8 @@ public function getServerHost(): string {
* isn't met
*/
private function getOverwriteHost() {
if ($this->config->getSystemValue('overwritehost') !== '' && $this->isOverwriteCondition()) {
return $this->config->getSystemValue('overwritehost');
if ($this->config->getSystemValueString('overwritehost') !== '' && $this->isOverwriteCondition()) {
return $this->config->getSystemValueString('overwritehost');
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(Session $userSession, IConfig $config) {
}

public function process(LoginData $loginData): LoginResult {
if ($loginData->isRememberLogin() && $this->config->getSystemValue('auto_logout', false) === false) {
if ($loginData->isRememberLogin() && !$this->config->getSystemValueBool('auto_logout', false)) {
$this->userSession->createRememberMeToken($loginData->getUser());
}

Expand Down
10 changes: 5 additions & 5 deletions lib/private/Authentication/Token/PublicKeyTokenProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ public function invalidateTokenById(string $uid, int $id) {
public function invalidateOldTokens() {
$this->cache->clear();

$olderThan = $this->time->getTime() - (int) $this->config->getSystemValue('session_lifetime', 60 * 60 * 24);
$olderThan = $this->time->getTime() - $this->config->getSystemValueInt('session_lifetime', 60 * 60 * 24);
$this->logger->debug('Invalidating session tokens older than ' . date('c', $olderThan), ['app' => 'cron']);
$this->mapper->invalidateOld($olderThan, IToken::DO_NOT_REMEMBER);
$rememberThreshold = $this->time->getTime() - (int) $this->config->getSystemValue('remember_login_cookie_lifetime', 60 * 60 * 24 * 15);
$rememberThreshold = $this->time->getTime() - $this->config->getSystemValueInt('remember_login_cookie_lifetime', 60 * 60 * 24 * 15);
$this->logger->debug('Invalidating remembered session tokens older than ' . date('c', $rememberThreshold), ['app' => 'cron']);
$this->mapper->invalidateOld($rememberThreshold, IToken::REMEMBER);
}
Expand Down Expand Up @@ -366,15 +366,15 @@ public function rotate(IToken $token, string $oldTokenId, string $newTokenId): I
}

private function encrypt(string $plaintext, string $token): string {
$secret = $this->config->getSystemValue('secret');
$secret = $this->config->getSystemValueString('secret');
return $this->crypto->encrypt($plaintext, $token . $secret);
}

/**
* @throws InvalidTokenException
*/
private function decrypt(string $cipherText, string $token): string {
$secret = $this->config->getSystemValue('secret');
$secret = $this->config->getSystemValueString('secret');
try {
return $this->crypto->decrypt($cipherText, $token . $secret);
} catch (\Exception $ex) {
Expand Down Expand Up @@ -404,7 +404,7 @@ private function decryptPassword(string $encryptedPassword, string $privateKey):
}

private function hashToken(string $token): string {
$secret = $this->config->getSystemValue('secret');
$secret = $this->config->getSystemValueString('secret');
return hash('sha512', $token . $secret);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/private/Collaboration/Collaborators/LookupPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct(IConfig $config,
}

public function search($search, $limit, $offset, ISearchResult $searchResult) {
$isGlobalScaleEnabled = $this->config->getSystemValue('gs.enabled', false);
$isGlobalScaleEnabled = $this->config->getSystemValueBool('gs.enabled', false);
$isLookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'yes') === 'yes';
$hasInternetConnection = $this->config->getSystemValueBool('has_internet_connection', true);

Expand All @@ -72,7 +72,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult) {
return false;
}

$lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com');
$lookupServerUrl = $this->config->getSystemValueString('lookup_server', 'https://lookup.nextcloud.com');
if (empty($lookupServerUrl)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function loadCommands(

try {
require_once __DIR__ . '/../../../core/register_command.php';
if ($this->config->getSystemValue('installed', false)) {
if ($this->config->getSystemValueBool('installed', false)) {
if (\OCP\Util::needUpgrade()) {
throw new NeedsUpdateException();
} elseif ($this->config->getSystemValueBool('maintenance')) {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/DB/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ protected function convertStatementToScript($statement) {
}

protected function getFilterExpression() {
return '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/';
return '/^' . preg_quote($this->config->getSystemValueString('dbtableprefix', 'oc_')) . '/';
}

protected function emit(string $sql, int $step, int $max): void {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/DB/OracleMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,6 @@ protected function convertStatementToScript($statement) {
}

protected function getFilterExpression() {
return '/^"' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/';
return '/^"' . preg_quote($this->config->getSystemValueString('dbtableprefix', 'oc_')) . '/';
}
}
2 changes: 1 addition & 1 deletion lib/private/DB/PgSqlTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function resynchronizeDatabaseSequences(Connection $conn) {
$databaseName = $conn->getDatabase();
$conn->getConfiguration()->setSchemaAssetsFilter(function ($asset) {
/** @var string|AbstractAsset $asset */
$filterExpression = '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/';
$filterExpression = '/^' . preg_quote($this->config->getSystemValueString('dbtableprefix', 'oc_')) . '/';
if ($asset instanceof AbstractAsset) {
return preg_match($filterExpression, $asset->getName()) !== false;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/private/Encryption/Keys/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private function getKeyWithUid(string $path, ?string $uid): string {

if (!array_key_exists('uid', $data) || $data['uid'] !== $uid) {
// If the migration is done we error out
$versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0.0');
$versionFromBeforeUpdate = $this->config->getSystemValueString('version', '0.0.0.0');
if (version_compare($versionFromBeforeUpdate, '20.0.0.1', '<=')) {
return $data['key'];
}
Expand Down Expand Up @@ -272,7 +272,7 @@ private function getKey($path): array {
$data = $this->view->file_get_contents($path);

// Version <20.0.0.1 doesn't have this
$versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0.0');
$versionFromBeforeUpdate = $this->config->getSystemValueString('version', '0.0.0.0');
if (version_compare($versionFromBeforeUpdate, '20.0.0.1', '<=')) {
$key = [
'key' => base64_encode($data),
Expand Down Expand Up @@ -335,7 +335,7 @@ private function getKey($path): array {
private function setKey($path, $key) {
$this->keySetPreparation(dirname($path));

$versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0.0');
$versionFromBeforeUpdate = $this->config->getSystemValueString('version', '0.0.0.0');
if (version_compare($versionFromBeforeUpdate, '20.0.0.1', '<=')) {
// Only store old format if this happens during the migration.
// TODO: Remove for 21
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Encryption/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function __construct(IConfig $config, LoggerInterface $logger, IL10N $l10
* @return bool true if enabled, false if not
*/
public function isEnabled() {
$installed = $this->config->getSystemValue('installed', false);
$installed = $this->config->getSystemValueBool('installed', false);
if (!$installed) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Encryption/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Util {
protected $config;

/** @var array paths excluded from encryption */
protected $excludedPaths;
protected array $excludedPaths = [];
protected IGroupManager $groupManager;
protected IUserManager $userManager;

Expand All @@ -94,7 +94,7 @@ public function __construct(
$this->config = $config;

$this->excludedPaths[] = 'files_encryption';
$this->excludedPaths[] = 'appdata_' . $config->getSystemValue('instanceid', null);
$this->excludedPaths[] = 'appdata_' . $config->getSystemValueString('instanceid');
$this->excludedPaths[] = 'files_external';
}

Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function __construct(\OC\Files\Storage\Storage $storage) {
$this->storage = $storage;
$this->storageId = $this->storage->getId();
$this->cache = $storage->getCache();
$this->cacheActive = !\OC::$server->getConfig()->getSystemValue('filesystem_cache_readonly', false);
$this->cacheActive = !\OC::$server->getConfig()->getSystemValueBool('filesystem_cache_readonly', false);
$this->lockingProvider = \OC::$server->getLockingProvider();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Mount/CacheMountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct(IConfig $config) {
* @return \OCP\Files\Mount\IMountPoint[]
*/
public function getMountsForUser(IUser $user, IStorageFactory $loader) {
$cacheBaseDir = $this->config->getSystemValue('cache_path', '');
$cacheBaseDir = $this->config->getSystemValueString('cache_path', '');
if ($cacheBaseDir !== '') {
$cacheDir = rtrim($cacheBaseDir, '/') . '/' . $user->getUID();
if (!file_exists($cacheDir)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Storage/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ public function changeLock($path, $type, ILockingProvider $provider) {

private function getLockLogger(): ?LoggerInterface {
if (is_null($this->shouldLogLocks)) {
$this->shouldLogLocks = \OC::$server->getConfig()->getSystemValue('filelocking.debug', false);
$this->shouldLogLocks = \OC::$server->getConfig()->getSystemValueBool('filelocking.debug', false);
$this->logger = $this->shouldLogLocks ? \OC::$server->get(LoggerInterface::class) : null;
}
return $this->logger;
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Storage/DAV.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ protected function init() {
$settings['authType'] = $this->authType;
}

$proxy = \OC::$server->getConfig()->getSystemValue('proxy', '');
$proxy = \OC::$server->getConfig()->getSystemValueString('proxy', '');
if ($proxy !== '') {
$settings['proxy'] = $proxy;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Files/Storage/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function __construct($arguments) {
$this->defUMask = $this->config->getSystemValue('localstorage.umask', 0022);

// support Write-Once-Read-Many file systems
$this->unlinkOnTruncate = $this->config->getSystemValue('localstorage.unlink_on_truncate', false);
$this->unlinkOnTruncate = $this->config->getSystemValueBool('localstorage.unlink_on_truncate', false);
}

public function __destruct() {
Expand Down Expand Up @@ -486,7 +486,7 @@ public function getSourcePath($path) {

$fullPath = $this->datadir . $path;
$currentPath = $path;
$allowSymlinks = $this->config->getSystemValue('localstorage.allowsymlinks', false);
$allowSymlinks = $this->config->getSystemValueBool('localstorage.allowsymlinks', false);
if ($allowSymlinks || $currentPath === '') {
return $fullPath;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Files/Template/TemplateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ public function initializeTemplateDirectory(string $path = null, string $userId

$defaultSkeletonDirectory = \OC::$SERVERROOT . '/core/skeleton';
$defaultTemplateDirectory = \OC::$SERVERROOT . '/core/skeleton/Templates';
$skeletonPath = $this->config->getSystemValue('skeletondirectory', $defaultSkeletonDirectory);
$skeletonTemplatePath = $this->config->getSystemValue('templatedirectory', $defaultTemplateDirectory);
$skeletonPath = $this->config->getSystemValueString('skeletondirectory', $defaultSkeletonDirectory);
$skeletonTemplatePath = $this->config->getSystemValueString('templatedirectory', $defaultTemplateDirectory);
$isDefaultSkeleton = $skeletonPath === $defaultSkeletonDirectory;
$isDefaultTemplates = $skeletonTemplatePath === $defaultTemplateDirectory;
$userLang = $this->l10nFactory->getUserLanguage($this->userManager->get($this->userId));
Expand Down
5 changes: 2 additions & 3 deletions lib/private/GlobalScale/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public function __construct(IConfig $config) {
* @return bool
*/
public function isGlobalScaleEnabled() {
$enabled = $this->config->getSystemValue('gs.enabled', false);
return $enabled !== false;
return $this->config->getSystemValueBool('gs.enabled', false);
}

/**
Expand All @@ -61,7 +60,7 @@ public function onlyInternalFederation() {
return false;
}

$enabled = $this->config->getSystemValue('gs.federation', 'internal');
$enabled = $this->config->getSystemValueString('gs.federation', 'internal');

return $enabled === 'internal';
}
Expand Down
Loading