diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2025-07-14 20:01:58 +0200 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2025-07-14 20:01:58 +0200 |
commit | 281931d8de066f3e8d5e3ce712dd2e7ae2389068 (patch) | |
tree | 3f9885fd9424586a37c2815719f4c5834958996d | |
parent | 41b88080043527b1a56026f00941b58340e7f6a6 (diff) | |
download | nextcloud-server-feat/noid/store-lexicon-default.tar.gz nextcloud-server-feat/noid/store-lexicon-default.zip |
feat(lexicon): save value from default closure if requestedfeat/noid/store-lexicon-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 35108ee8ded..570dcca4a51 100644 --- a/lib/private/AppConfig.php +++ b/lib/private/AppConfig.php @@ -1634,7 +1634,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 f5289ba787a..452a2649cca 100644 --- a/lib/private/Config/UserConfig.php +++ b/lib/private/Config/UserConfig.php @@ -1929,7 +1929,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 8d07c0e17d9..f3257a795eb 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(ConfigLexiconPreset $preset): ?string { + public function getDefault(ConfigLexiconPreset $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 */ |