summaryrefslogtreecommitdiffstats
path: root/core/command/config
diff options
context:
space:
mode:
Diffstat (limited to 'core/command/config')
-rw-r--r--core/command/config/app/deleteconfig.php81
-rw-r--r--core/command/config/app/getconfig.php93
-rw-r--r--core/command/config/app/setconfig.php89
-rw-r--r--core/command/config/system/deleteconfig.php2
-rw-r--r--core/command/config/system/getconfig.php2
-rw-r--r--core/command/config/system/setconfig.php2
6 files changed, 266 insertions, 3 deletions
diff --git a/core/command/config/app/deleteconfig.php b/core/command/config/app/deleteconfig.php
new file mode 100644
index 00000000000..0031142358e
--- /dev/null
+++ b/core/command/config/app/deleteconfig.php
@@ -0,0 +1,81 @@
+<?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\App;
+
+use OC\Core\Command\Base;
+use OCP\IConfig;
+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 DeleteConfig extends Base {
+ /** * @var IConfig */
+ protected $config;
+
+ /**
+ * @param IConfig $config
+ */
+ public function __construct(IConfig $config) {
+ parent::__construct();
+ $this->config = $config;
+ }
+
+ protected function configure() {
+ parent::configure();
+
+ $this
+ ->setName('config:app:delete')
+ ->setDescription('Delete an app config value')
+ ->addArgument(
+ 'app',
+ InputArgument::REQUIRED,
+ 'Name of the app'
+ )
+ ->addArgument(
+ 'name',
+ InputArgument::REQUIRED,
+ 'Name of the config to delete'
+ )
+ ->addOption(
+ 'error-if-not-exists',
+ null,
+ InputOption::VALUE_NONE,
+ 'Checks whether the config exists before deleting it'
+ )
+ ;
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output) {
+ $appName = $input->getArgument('app');
+ $configName = $input->getArgument('name');
+
+ if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->config->getAppKeys($appName))) {
+ $output->writeln('<error>Config ' . $configName . ' could not be deleted because it did not exist</error>');
+ return 1;
+ }
+
+ $this->config->deleteAppValue($appName, $configName);
+ $output->writeln('<info>System config value ' . $configName . ' deleted</info>');
+ return 0;
+ }
+}
diff --git a/core/command/config/app/getconfig.php b/core/command/config/app/getconfig.php
new file mode 100644
index 00000000000..08b263627ef
--- /dev/null
+++ b/core/command/config/app/getconfig.php
@@ -0,0 +1,93 @@
+<?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\App;
+
+use OC\Core\Command\Base;
+use OCP\IConfig;
+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 GetConfig extends Base {
+ /** * @var IConfig */
+ protected $config;
+
+ /**
+ * @param IConfig $config
+ */
+ public function __construct(IConfig $config) {
+ parent::__construct();
+ $this->config = $config;
+ }
+
+ protected function configure() {
+ parent::configure();
+
+ $this
+ ->setName('config:app:get')
+ ->setDescription('Set an app config value')
+ ->addArgument(
+ 'app',
+ InputArgument::REQUIRED,
+ 'Name of the app'
+ )
+ ->addArgument(
+ 'name',
+ InputArgument::REQUIRED,
+ 'Name of the config to get'
+ )
+ ->addOption(
+ 'default-value',
+ null,
+ InputOption::VALUE_OPTIONAL,
+ 'If no default value is set and the config does not exist, the command will exit with 1'
+ )
+ ;
+ }
+
+ /**
+ * Executes the current command.
+ *
+ * @param InputInterface $input An InputInterface instance
+ * @param OutputInterface $output An OutputInterface instance
+ * @return null|int null or 0 if everything went fine, or an error code
+ */
+ protected function execute(InputInterface $input, OutputInterface $output) {
+ $appName = $input->getArgument('app');
+ $configName = $input->getArgument('name');
+ $defaultValue = $input->getOption('default-value');
+
+ if (!in_array($configName, $this->config->getAppKeys($appName)) && !$input->hasParameterOption('--default-value')) {
+ return 1;
+ }
+
+ if (!in_array($configName, $this->config->getAppKeys($appName))) {
+ $configValue = $defaultValue;
+ } else {
+ $configValue = $this->config->getAppValue($appName, $configName);
+ }
+
+ $this->writeMixedInOutputFormat($input, $output, $configValue);
+ return 0;
+ }
+}
diff --git a/core/command/config/app/setconfig.php b/core/command/config/app/setconfig.php
new file mode 100644
index 00000000000..91775094fdd
--- /dev/null
+++ b/core/command/config/app/setconfig.php
@@ -0,0 +1,89 @@
+<?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\App;
+
+use OC\Core\Command\Base;
+use OCP\IConfig;
+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 IConfig */
+ protected $config;
+
+ /**
+ * @param IConfig $config
+ */
+ public function __construct(IConfig $config) {
+ parent::__construct();
+ $this->config = $config;
+ }
+
+ protected function configure() {
+ parent::configure();
+
+ $this
+ ->setName('config:app:set')
+ ->setDescription('Set an app config value')
+ ->addArgument(
+ 'app',
+ InputArgument::REQUIRED,
+ 'Name of the app'
+ )
+ ->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) {
+ $appName = $input->getArgument('app');
+ $configName = $input->getArgument('name');
+
+ if (!in_array($configName, $this->config->getAppKeys($appName)) && $input->hasParameterOption('--update-only')) {
+ $output->writeln('<comment>Value not updated, as it has not been set before.</comment>');
+ return 1;
+ }
+
+ $configValue = $input->getOption('value');
+ $this->config->setAppValue($appName, $configName, $configValue);
+
+ $output->writeln('<info>Config value ' . $configName . ' for app ' . $appName . ' set to ' . $configValue . '</info>');
+ return 0;
+ }
+}
diff --git a/core/command/config/system/deleteconfig.php b/core/command/config/system/deleteconfig.php
index c4930a8d3aa..49bc2bc8c03 100644
--- a/core/command/config/system/deleteconfig.php
+++ b/core/command/config/system/deleteconfig.php
@@ -49,7 +49,7 @@ class DeleteConfig extends Base {
->addArgument(
'name',
InputArgument::REQUIRED,
- 'Name of the config to set'
+ 'Name of the config to delete'
)
->addOption(
'error-if-not-exists',
diff --git a/core/command/config/system/getconfig.php b/core/command/config/system/getconfig.php
index 1ed3b36da36..df9b1a96ef3 100644
--- a/core/command/config/system/getconfig.php
+++ b/core/command/config/system/getconfig.php
@@ -55,7 +55,7 @@ class GetConfig extends Base {
'default-value',
null,
InputOption::VALUE_OPTIONAL,
- 'If no default value is set and the config does not exist, an error is thrown'
+ 'If no default value is set and the config does not exist, the command will exit with 1'
)
;
}
diff --git a/core/command/config/system/setconfig.php b/core/command/config/system/setconfig.php
index 6eda9db8f93..cb2f9fe616f 100644
--- a/core/command/config/system/setconfig.php
+++ b/core/command/config/system/setconfig.php
@@ -70,7 +70,7 @@ class SetConfig extends Base {
$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>');
+ $output->writeln('<comment>Value not updated, as it has not been set before.</comment>');
return 1;
}
$configValue = $input->getOption('value');