From db6dba96194a63eeb68c5240da0bf686f79a0c59 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 9 Jun 2016 15:14:15 +0200 Subject: Allow deleting a setting --- core/Command/User/Setting.php | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'core') 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('The setting does not exist for user "' . $uid . '".'); + return 1; + } + + $this->config->deleteUserValue($uid, $app, $key); + } else if ($value !== null) { $output->writeln($value); } else { -- cgit v1.2.3