From a83eac3762fff010e154e2f80cb4f0bd716d8d43 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 8 May 2015 10:54:40 +0200 Subject: Add a command to set a system config value --- core/command/config/system/setconfig.php | 83 ++++++++++++++++++++++++++++++++ core/register_command.php | 1 + 2 files changed, 84 insertions(+) create mode 100644 core/command/config/system/setconfig.php (limited to 'core') diff --git a/core/command/config/system/setconfig.php b/core/command/config/system/setconfig.php new file mode 100644 index 00000000000..e2c901cc789 --- /dev/null +++ b/core/command/config/system/setconfig.php @@ -0,0 +1,83 @@ + + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OC\Core\Command\Config\System; + +use OC\Core\Command\Base; +use OC\SystemConfig; +use OCP\IAppConfig; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +class SetConfig extends Base { + /** * @var SystemConfig */ + protected $systemConfig; + + /** + * @param SystemConfig $systemConfig + */ + public function __construct(SystemConfig $systemConfig) { + parent::__construct(); + $this->systemConfig = $systemConfig; + } + + protected function configure() { + parent::configure(); + + $this + ->setName('config:system:set') + ->setDescription('Set a system config value') + ->addArgument( + 'name', + InputArgument::REQUIRED, + 'Name of the config to set' + ) + ->addOption( + 'value', + null, + InputOption::VALUE_REQUIRED, + 'The new value of the config' + ) + ->addOption( + 'update-only', + null, + InputOption::VALUE_NONE, + 'Only updates the value, if it is not set before, it is not being added' + ) + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) { + $configName = $input->getArgument('name'); + + if (!in_array($configName, $this->systemConfig->getKeys()) && $input->hasParameterOption('--update-only')) { + $output->writeln('Value has not been updated, as it has not been set before.'); + return 1; + } + $configValue = $input->getOption('value'); + + $this->systemConfig->setValue($configName, $configValue); + $output->writeln('System config value ' . $configName . ' set to ' . $configValue . ''); + return 0; + } +} diff --git a/core/register_command.php b/core/register_command.php index b4c3576bb4d..f3c0a375c5b 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -41,6 +41,7 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) { $application->add(new OC\Core\Command\Background\Ajax(\OC::$server->getConfig())); $application->add(new OC\Core\Command\Config\ListConfigs(\OC::$server->getSystemConfig(), \OC::$server->getAppConfig())); + $application->add(new OC\Core\Command\Config\System\SetConfig(\OC::$server->getSystemConfig())); $application->add(new OC\Core\Command\Db\GenerateChangeScript()); $application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory())); -- cgit v1.2.3