From b298b53fda076b3b5aa3998eadf6b6dd61ce2643 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 27 Jul 2021 08:35:46 +0200 Subject: [PATCH] PreferencesCommand: Automatically set the resource as config backend --- .../clicommands/PreferencesCommand.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/modules/migrate/application/clicommands/PreferencesCommand.php b/modules/migrate/application/clicommands/PreferencesCommand.php index 1935e2250..63f4894be 100644 --- a/modules/migrate/application/clicommands/PreferencesCommand.php +++ b/modules/migrate/application/clicommands/PreferencesCommand.php @@ -27,6 +27,7 @@ class PreferencesCommand extends Command * OPTIONS: * * --resource= The resource to use, if no current database config backend is configured. + * --no-set-config-backend Do not set the given resource as config backend automatically */ public function indexAction() { @@ -80,8 +81,22 @@ class PreferencesCommand extends Command if ($rc > 0) { Logger::error('Failed to migrate some user preferences'); exit($rc); - } else { - Logger::info('Successfully migrated all local user preferences to database'); } + + if ($this->params->has('resource') && ! $this->params->has('no-set-config-backend')) { + $appConfig = Config::app(); + $globalConfig = $appConfig->getSection('global'); + $globalConfig['config_backend'] = 'db'; + $globalConfig['config_resource'] = $resource; + + try { + $appConfig->saveIni(); + } catch (NotWritableError $e) { + Logger::error('Failed to update general configuration: %s', $e->getMessage()); + exit(256); + } + } + + Logger::info('Successfully migrated all local user preferences to database'); } }