diff --git a/lib/private/AppConfig.php b/lib/private/AppConfig.php index be701f3da53d8..af398197c5873 100644 --- a/lib/private/AppConfig.php +++ b/lib/private/AppConfig.php @@ -163,7 +163,7 @@ public function searchKeys(string $app, string $prefix = '', bool $lazy = false) public function hasKey(string $app, string $key, ?bool $lazy = false): bool { $this->assertParams($app, $key); $this->loadConfig($app, $lazy ?? true); - $this->matchAndApplyLexiconDefinition($app, $key); + $this->matchAndApplyLexiconDefinition($app, $key, $lazy); $hasLazy = isset($this->lazyCache[$app][$key]); $hasFast = isset($this->fastCache[$app][$key]); diff --git a/lib/private/Config/UserConfig.php b/lib/private/Config/UserConfig.php index 5a5488e34187e..3665f92b8573b 100644 --- a/lib/private/Config/UserConfig.php +++ b/lib/private/Config/UserConfig.php @@ -158,7 +158,12 @@ public function getKeys(string $userId, string $app): array { public function hasKey(string $userId, string $app, string $key, ?bool $lazy = false): bool { $this->assertParams($userId, $app, $key); $this->loadConfig($userId, $lazy); - $this->matchAndApplyLexiconDefinition($userId, $app, $key); + + // to avoid a loop on hasKey(), we set $default to null + // as matchAndApplyLexiconDefinition() will only search + // for $default if requested + $default = null; + $this->matchAndApplyLexiconDefinition($userId, $app, $key, $lazy, default: $default); if ($lazy === null) { $appCache = $this->getValues($userId, $app); @@ -1970,15 +1975,18 @@ private function matchAndApplyLexiconDefinition( } $enforcedValue = $this->config->getSystemValue('lexicon.default.userconfig.enforced', [])[$app][$key] ?? false; + // only look for default if needed + if ($default === null) { + return !$enforcedValue; + } + if (!$enforcedValue && $this->hasKey($userId, $app, $key, $lazy)) { // if key exists there should be no need to extract default return true; } - // only look for default if needed, default from Lexicon got priority if not overwritten by admin - if ($default !== null) { - $default = $this->getSystemDefault($app, $configValue) ?? $configValue->getDefault($this->presetManager->getLexiconPreset()) ?? $default; - } + // default from Lexicon got priority if not overwritten by admin + $default = $this->getSystemDefault($app, $configValue) ?? $configValue->getDefault($this->presetManager->getLexiconPreset()) ?? $default; // returning false will make get() returning $default and set() not changing value in database return !$enforcedValue;