diff options
author | Joas Schilling <coding@schilljs.com> | 2016-06-09 15:07:06 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2016-07-13 18:43:43 +0200 |
commit | c3c7a5fd2c167b297b8186af693685b3d430bdb9 (patch) | |
tree | 56990598fcb4852fc9e5a352c45a32a8d255537d /core/Command | |
parent | b96f0c99b0cf20b6997e1019c624c1848c006434 (diff) | |
download | nextcloud-server-c3c7a5fd2c167b297b8186af693685b3d430bdb9.tar.gz nextcloud-server-c3c7a5fd2c167b297b8186af693685b3d430bdb9.zip |
Allow setting values
Diffstat (limited to 'core/Command')
-rw-r--r-- | core/Command/User/Setting.php | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/core/Command/User/Setting.php b/core/Command/User/Setting.php index 887439ba2e0..568f1cc2d09 100644 --- a/core/Command/User/Setting.php +++ b/core/Command/User/Setting.php @@ -76,16 +76,32 @@ class Setting extends Base { '' ) ->addOption( + 'ignore-missing-user', + null, + InputOption::VALUE_NONE, + 'Use this option to ignore errors when the user does not exist' + ) + + // Get + ->addOption( 'default-value', null, InputOption::VALUE_REQUIRED, '(Only applicable on get) If no default value is set and the config does not exist, the command will exit with 1' ) + + // Set ->addOption( - 'ignore-missing-user', + 'value', + null, + InputOption::VALUE_REQUIRED, + 'The new value of the config' + ) + ->addOption( + 'update-only', null, InputOption::VALUE_NONE, - 'Use this option to ignore errors when the user does not exist' + 'Only updates the value, if it is not set before, it is not being added' ) ; } @@ -97,7 +113,14 @@ 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 getting a single setting.'); + } + + 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".'); } } @@ -115,7 +138,15 @@ class Setting extends Base { if ($key !== '') { $value = $this->config->getUserValue($uid, $app, $key, null); - if ($value !== null) { + if ($input->hasParameterOption('--value')) { + if ($input->hasParameterOption('--update-only') && $value === null) { + $output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>'); + return 1; + } + + $this->config->setUserValue($uid, $app, $key, $input->getOption('value')); + + } else if ($value !== null) { $output->writeln($value); } else { if ($input->hasParameterOption('--default-value')) { |