diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2025-07-15 12:45:32 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2025-07-16 11:56:28 -0100 |
commit | 55a0e85fbd9aeff41c444b9c9b2ec7fa6c72288d (patch) | |
tree | 1e0c71b219fec335caaeca36dcb2ed4d993ed28c | |
parent | 1dbd22e317c09a1471befe995755f0523573b2b7 (diff) | |
download | nextcloud-server-feat/noid/lexicon-store-on-get-as-default.tar.gz nextcloud-server-feat/noid/lexicon-store-on-get-as-default.zip |
feat(lexicon): optionally store in database default if nonefeat/noid/lexicon-store-on-get-as-default
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r-- | lib/private/AppConfig.php | 5 | ||||
-rw-r--r-- | lib/private/Config/UserConfig.php | 5 | ||||
-rw-r--r-- | lib/unstable/Config/Lexicon/ConfigLexiconEntry.php | 5 |
3 files changed, 11 insertions, 4 deletions
diff --git a/lib/private/AppConfig.php b/lib/private/AppConfig.php index 0eb91fb1be4..ba4bb2a00ce 100644 --- a/lib/private/AppConfig.php +++ b/lib/private/AppConfig.php @@ -1642,7 +1642,10 @@ class AppConfig implements IAppConfig { $lazy = $configValue->isLazy(); // only look for default if needed, default from Lexicon got priority if ($default !== null) { - $default = $configValue->getDefault($this->getLexiconPreset()) ?? $default; + $default = $configValue->getDefault($this->getLexiconPreset(), $saveIt) ?? $default; + if ($saveIt ?? false) { + $this->setTypedValue($app, $key, $default, $lazy, $type); + } } if ($configValue->isFlagged(self::FLAG_SENSITIVE)) { diff --git a/lib/private/Config/UserConfig.php b/lib/private/Config/UserConfig.php index fb0bf954f57..0b22cc6f126 100644 --- a/lib/private/Config/UserConfig.php +++ b/lib/private/Config/UserConfig.php @@ -1936,7 +1936,10 @@ class UserConfig implements IUserConfig { // 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->getLexiconPreset()) ?? $default; + $default = $this->getSystemDefault($app, $configValue) ?? $configValue->getDefault($this->getLexiconPreset(), $saveIt) ?? $default; + if ($saveIt ?? false) { + $this->setTypedValue($userId, $app, $key, $default, $lazy, $flags, $type); + } } // returning false will make get() returning $default and set() not changing value in database diff --git a/lib/unstable/Config/Lexicon/ConfigLexiconEntry.php b/lib/unstable/Config/Lexicon/ConfigLexiconEntry.php index 068d89ce764..cb29823dc83 100644 --- a/lib/unstable/Config/Lexicon/ConfigLexiconEntry.php +++ b/lib/unstable/Config/Lexicon/ConfigLexiconEntry.php @@ -130,7 +130,7 @@ class ConfigLexiconEntry { * @return string|null NULL if no default is set * @experimental 31.0.0 */ - public function getDefault(Preset $preset): ?string { + public function getDefault(Preset $preset, ?bool &$saveIt = null): ?string { if ($this->default !== null) { return $this->default; } @@ -139,9 +139,10 @@ class ConfigLexiconEntry { return null; } + $saveIt = false; if ($this->defaultRaw instanceof Closure) { /** @psalm-suppress MixedAssignment we expect closure to returns string|int|float|bool|array */ - $this->defaultRaw = ($this->defaultRaw)($preset); + $this->defaultRaw = ($this->defaultRaw)($preset, $saveIt); } /** @psalm-suppress MixedArgument closure should be managed previously */ |