mirror of
https://github.com/nextcloud/server.git
synced 2026-06-12 18:21:40 -04:00
feat(lexicon): save value from default closure if requested
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
This commit is contained in:
parent
41b8808004
commit
281931d8de
3 changed files with 11 additions and 4 deletions
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Reference in a new issue