summaryrefslogtreecommitdiffstats
path: root/core/command
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-05-08 10:54:40 +0200
committerJoas Schilling <nickvergessen@owncloud.com>2015-07-07 11:18:25 +0200
commita83eac3762fff010e154e2f80cb4f0bd716d8d43 (patch)
tree61b5cf437e648d5c10ad906d9ed33054e3f344b0 /core/command
parent5370bba0b69aaba94567604ab99661a528d5b052 (diff)
downloadnextcloud-server-a83eac3762fff010e154e2f80cb4f0bd716d8d43.tar.gz
nextcloud-server-a83eac3762fff010e154e2f80cb4f0bd716d8d43.zip
Add a command to set a system config value
Diffstat (limited to 'core/command')
-rw-r--r--core/command/config/system/setconfig.php83
1 files changed, 83 insertions, 0 deletions
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 @@
+<?php
+/**
+ * @author Joas Schilling <nickvergessen@owncloud.com>
+ *
+ * @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 <http://www.gnu.org/licenses/>
+ *
+ */
+
+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('<comment>Value has not been updated, as it has not been set before.</comment>');
+ return 1;
+ }
+ $configValue = $input->getOption('value');
+
+ $this->systemConfig->setValue($configName, $configValue);
+ $output->writeln('<info>System config value ' . $configName . ' set to ' . $configValue . '</info>');
+ return 0;
+ }
+}