mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #54520 from nextcloud/fix/noid/preset-for-userconfig
feat(preset): compare userconfig lexicon entries
This commit is contained in:
commit
18351be65c
4 changed files with 48 additions and 13 deletions
|
|
@ -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'], '<comment>' . ($item['value'] ?? '') . '</comment>', ...($item['defaults'] ?? [])]);
|
||||
$table->addRow([$appId, $item['config'], $item['entry']['key'], '<comment>' . ($item['value'] ?? '') . '</comment>', ...($item['defaults'] ?? [])]);
|
||||
}
|
||||
}
|
||||
$table->render();
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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<string, list<array{defaults: array{CLUB: null|string, FAMILY: null|string, LARGE: null|string, MEDIUM: null|string, NONE: null|string, PRIVATE: null|string, SCHOOL: null|string, SHARED: null|string, SMALL: null|string, UNIVERSITY: null|string}, entry: array{definition: string, deprecated: bool, key: string, lazy: bool, note: string, type: 'ARRAY'|'BOOL'|'FLOAT'|'INT'|'MIXED'|'STRING'}, value?: mixed}>>
|
||||
* @return array<string, list<array{config: string, defaults: array{CLUB: null|string, FAMILY: null|string, LARGE: null|string, MEDIUM: null|string, NONE: null|string, PRIVATE: null|string, SCHOOL: null|string, SHARED: null|string, SMALL: null|string, UNIVERSITY: null|string}, entry: array{definition: string, deprecated: bool, key: string, lazy: bool, note: string, type: 'ARRAY'|'BOOL'|'FLOAT'|'INT'|'MIXED'|'STRING'}, value?: mixed}>>
|
||||
*/
|
||||
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<array{config: string, defaults: array{CLUB: null|string, FAMILY: null|string, LARGE: null|string, MEDIUM: null|string, NONE: null|string, PRIVATE: null|string, SCHOOL: null|string, SHARED: null|string, SMALL: null|string, UNIVERSITY: null|string}, entry: array{definition: string, deprecated: bool, key: string, lazy: bool, note: string, type: 'ARRAY'|'BOOL'|'FLOAT'|'INT'|'MIXED'|'STRING'}, value?: mixed}>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1999,8 +1999,7 @@ class UserConfig implements IUserConfig {
|
|||
* @param string $appId
|
||||
*
|
||||
* @return array{entries: array<string, Entry>, aliases: array<string, string>, 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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue