diff --git a/core/Command/Config/Preset.php b/core/Command/Config/Preset.php index b23f0378ff6..fc6c2d8abd9 100644 --- a/core/Command/Config/Preset.php +++ b/core/Command/Config/Preset.php @@ -44,10 +44,10 @@ class Preset extends Base { $list = $this->presetManager->retrieveLexiconPreset(); if ($input->getOption('output') === 'plain') { $table = new Table($output); - $table->setHeaders(['app', 'config key', 'value', ...array_map(static fn (ConfigLexiconPreset $p): string => $p->name, ConfigLexiconPreset::cases())]); + $table->setHeaders(['app', 'config', 'config key', 'value', ...array_map(static fn (ConfigLexiconPreset $p): string => $p->name, ConfigLexiconPreset::cases())]); foreach ($list as $appId => $entries) { foreach ($entries as $item) { - $table->addRow([$appId, $item['entry']['key'], '' . ($item['value'] ?? '') . '', ...($item['defaults'] ?? [])]); + $table->addRow([$appId, $item['config'], $item['entry']['key'], '' . ($item['value'] ?? '') . '', ...($item['defaults'] ?? [])]); } } $table->render(); diff --git a/lib/private/AppConfig.php b/lib/private/AppConfig.php index 77730e75895..269e27609b2 100644 --- a/lib/private/AppConfig.php +++ b/lib/private/AppConfig.php @@ -1232,6 +1232,7 @@ class AppConfig implements IAppConfig { * * @param bool $reload set to TRUE to refill cache instantly after clearing it * + * @internal * @since 29.0.0 */ public function clearCache(bool $reload = false): void { diff --git a/lib/private/Config/PresetManager.php b/lib/private/Config/PresetManager.php index 3034d1a0274..0e0bb07ed71 100644 --- a/lib/private/Config/PresetManager.php +++ b/lib/private/Config/PresetManager.php @@ -13,6 +13,7 @@ use OC\AppConfig; use OC\Installer; use OCP\App\AppPathNotFoundException; use OCP\App\IAppManager; +use OCP\Config\IUserConfig; use OCP\Config\Lexicon\Preset; use OCP\Exceptions\AppConfigUnknownKeyException; use OCP\IAppConfig; @@ -65,7 +66,7 @@ class PresetManager { * * **Warning** This method MUST be considered resource-needy! * - * @return array> + * @return array> */ public function retrieveLexiconPreset(?string $appId = null): array { if ($appId === null) { @@ -77,17 +78,41 @@ class PresetManager { return $apps; } - /** @var AppConfig|null $appConfig */ - $appConfig = Server::get(IAppConfig::class); - $lexicon = $appConfig->getConfigDetailsFromLexicon($appId); + return [ + $appId => array_merge( + $this->extractLexiconPresetFromConfigClass($appId, 'app', Server::get(IAppConfig::class)), + $this->extractLexiconPresetFromConfigClass($appId, 'user', Server::get(IUserConfig::class)) + ), + ]; + } + + /** + * @param string $appId + * + * @return list + */ + private function extractLexiconPresetFromConfigClass( + string $appId, + string $configType, + AppConfig|UserConfig $config, + ): array { $presets = []; + $lexicon = $config->getConfigDetailsFromLexicon($appId); foreach ($lexicon['entries'] as $entry) { $defaults = []; foreach (Preset::cases() as $case) { // for each case, we need to use a fresh IAppConfig with clear cache // cloning to avoid conflict while emulating preset - $newConfig = clone $appConfig; - $newConfig->clearCache(); // needed to ignore cache and rebuild default + $newConfig = clone $config; + if ($newConfig instanceof AppConfig) { + // needed to ignore cache and rebuild default + $newConfig->clearCache(); + } + if ($newConfig instanceof UserConfig) { + // in the case of IUserConfig, clear all users' cache + $newConfig->clearCacheAll(); + } + $newLexicon = $newConfig->getLexiconEntry($appId, $entry->getKey()); $defaults[$case->name] = $newLexicon?->getDefault($case); } @@ -99,6 +124,7 @@ class PresetManager { } $details = [ + 'config' => $configType, 'entry' => [ 'key' => $entry->getKey(), 'type' => $entry->getValueType()->name, @@ -111,14 +137,17 @@ class PresetManager { ]; try { - $details['value'] = $appConfig->getDetails($appId, $entry->getKey())['value']; + // not interested if a users config value is already set + if ($config instanceof AppConfig) { + $details['value'] = $config->getDetails($appId, $entry->getKey())['value']; + } } catch (AppConfigUnknownKeyException) { } $presets[] = $details; } - return [$appId => $presets]; + return $presets; } /** diff --git a/lib/private/Config/UserConfig.php b/lib/private/Config/UserConfig.php index 4ddad3ec2f2..3a78d91ee76 100644 --- a/lib/private/Config/UserConfig.php +++ b/lib/private/Config/UserConfig.php @@ -1999,8 +1999,7 @@ class UserConfig implements IUserConfig { * @param string $appId * * @return array{entries: array, aliases: array, strictness: Strictness} - *@internal - * + * @internal */ public function getConfigDetailsFromLexicon(string $appId): array { if (!array_key_exists($appId, $this->configLexiconDetails)) { @@ -2024,7 +2023,13 @@ class UserConfig implements IUserConfig { return $this->configLexiconDetails[$appId]; } - private function getLexiconEntry(string $appId, string $key): ?Entry { + /** + * get Lexicon Entry using appId and config key entry + * + * @return Entry|null NULL if entry does not exist in user's Lexicon + * @internal + */ + public function getLexiconEntry(string $appId, string $key): ?Entry { return $this->getConfigDetailsFromLexicon($appId)['entries'][$key] ?? null; }