fix(settings): Check all values first, then apply them

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
This commit is contained in:
Marcel Klehr 2026-03-26 11:32:42 +01:00 committed by backportbot[bot]
parent 29fe9db52a
commit b1d29c0b29

View file

@ -44,15 +44,20 @@ class AISettingsController extends Controller {
continue;
}
try {
$value = json_encode($settings[$key], flags: \JSON_THROW_ON_ERROR);
$settings[$key] = json_encode($settings[$key], flags: \JSON_THROW_ON_ERROR);
} catch (\JsonException) {
return new DataResponse(['error' => "Setting value for '$key' must be JSON-compatible"], Http::STATUS_BAD_REQUEST);
}
$changed = $this->appConfig->setValueString('core', $key, $value, lazy: in_array($key, \OC\TaskProcessing\Manager::LAZY_CONFIG_KEYS, true));
}
foreach ($keys as $key) {
if (!isset($settings[$key])) {
continue;
}
$changed = $this->appConfig->setValueString('core', $key, $settings[$key], lazy: in_array($key, \OC\TaskProcessing\Manager::LAZY_CONFIG_KEYS, true));
if ($changed) {
$this->eventDispatcher->dispatchTyped(new CriticalActionPerformedEvent(
'AI configuration was changed by user %s: %s was set to %s',
[$this->userId, $key, $value]
[$this->userId, $key, $settings[$key]]
));
}
}