summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-06-09 15:14:15 +0200
committerJoas Schilling <coding@schilljs.com>2016-07-13 18:43:46 +0200
commitdb6dba96194a63eeb68c5240da0bf686f79a0c59 (patch)
tree46a955050de49e5c80b8a87dbe86300f6c6d6764 /core
parentc3c7a5fd2c167b297b8186af693685b3d430bdb9 (diff)
downloadnextcloud-server-db6dba96194a63eeb68c5240da0bf686f79a0c59.tar.gz
nextcloud-server-db6dba96194a63eeb68c5240da0bf686f79a0c59.zip
Allow deleting a setting
Diffstat (limited to 'core')
-rw-r--r--core/Command/User/Setting.php42
1 files changed, 40 insertions, 2 deletions
diff --git a/core/Command/User/Setting.php b/core/Command/User/Setting.php
index 568f1cc2d09..a5ce74b5a79 100644
--- a/core/Command/User/Setting.php
+++ b/core/Command/User/Setting.php
@@ -95,7 +95,7 @@ class Setting extends Base {
'value',
null,
InputOption::VALUE_REQUIRED,
- 'The new value of the config'
+ 'The new value of the setting'
)
->addOption(
'update-only',
@@ -103,6 +103,20 @@ class Setting extends Base {
InputOption::VALUE_NONE,
'Only updates the value, if it is not set before, it is not being added'
)
+
+ // Delete
+ ->addOption(
+ 'delete',
+ null,
+ InputOption::VALUE_NONE,
+ 'Specify this option to delete the config'
+ )
+ ->addOption(
+ 'error-if-not-exists',
+ null,
+ InputOption::VALUE_NONE,
+ 'Checks whether the setting exists before deleting it'
+ )
;
}
@@ -113,15 +127,31 @@ class Setting extends Base {
}
if ($input->getArgument('key') === '' && $input->hasParameterOption('--default-value')) {
- throw new \InvalidArgumentException('The "default-value" option can only be used when getting a single setting.');
+ throw new \InvalidArgumentException('The "default-value" option can only be used when specifying a key.');
}
+ if ($input->getArgument('key') === '' && $input->hasParameterOption('--value')) {
+ throw new \InvalidArgumentException('The "value" option can only be used when specifying a key.');
+ }
if ($input->hasParameterOption('--value') && $input->hasParameterOption('--default-value')) {
throw new \InvalidArgumentException('The "value" option can not be used together with "default-value".');
}
if ($input->hasParameterOption('--update-only') && !$input->hasParameterOption('--value')) {
throw new \InvalidArgumentException('The "update-only" option can only be used together with "value".');
}
+
+ if ($input->getArgument('key') === '' && $input->hasParameterOption('--delete')) {
+ throw new \InvalidArgumentException('The "delete" option can only be used when specifying a key.');
+ }
+ if ($input->hasParameterOption('--delete') && $input->hasParameterOption('--default-value')) {
+ throw new \InvalidArgumentException('The "value" option can not be used together with "default-value".');
+ }
+ if ($input->hasParameterOption('--delete') && $input->hasParameterOption('--value')) {
+ throw new \InvalidArgumentException('The "value" option can not be used together with "value".');
+ }
+ if ($input->hasParameterOption('--error-if-not-exists') && !$input->hasParameterOption('--delete')) {
+ throw new \InvalidArgumentException('The "error-if-not-exists" option can only be used together with "delete".');
+ }
}
protected function execute(InputInterface $input, OutputInterface $output) {
@@ -146,6 +176,14 @@ class Setting extends Base {
$this->config->setUserValue($uid, $app, $key, $input->getOption('value'));
+ } else if ($input->hasParameterOption('--delete')) {
+ if ($input->hasParameterOption('--error-if-not-exists') && $value === null) {
+ $output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>');
+ return 1;
+ }
+
+ $this->config->deleteUserValue($uid, $app, $key);
+
} else if ($value !== null) {
$output->writeln($value);
} else {