aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-12-09 14:26:17 +0100
committerJoas Schilling <nickvergessen@owncloud.com>2016-01-14 15:02:54 +0100
commita06f0256a9ce0f928b6b658b1df92bafbf6b6086 (patch)
tree1283a9d2fcf58fdecf17e9b8b5539795b5237371 /core
parent00ab50defc7a683907df59fd503b24a35decf962 (diff)
downloadnextcloud-server-a06f0256a9ce0f928b6b658b1df92bafbf6b6086.tar.gz
nextcloud-server-a06f0256a9ce0f928b6b658b1df92bafbf6b6086.zip
Allow deleting a nested system config value
Diffstat (limited to 'core')
-rw-r--r--core/command/config/system/deleteconfig.php60
-rw-r--r--core/command/config/system/setconfig.php2
2 files changed, 52 insertions, 10 deletions
diff --git a/core/command/config/system/deleteconfig.php b/core/command/config/system/deleteconfig.php
index e64ff32ac71..374f5ac69b7 100644
--- a/core/command/config/system/deleteconfig.php
+++ b/core/command/config/system/deleteconfig.php
@@ -48,8 +48,8 @@ class DeleteConfig extends Base {
->setDescription('Delete a system config value')
->addArgument(
'name',
- InputArgument::REQUIRED,
- 'Name of the config to delete'
+ InputArgument::REQUIRED | InputArgument::IS_ARRAY,
+ 'Name of the config to delete, specify multiple for array parameter'
)
->addOption(
'error-if-not-exists',
@@ -61,15 +61,57 @@ class DeleteConfig extends Base {
}
protected function execute(InputInterface $input, OutputInterface $output) {
- $configName = $input->getArgument('name');
+ $configNames = $input->getArgument('name');
+ $configName = $configNames[0];
- if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) {
- $output->writeln('<error>System config ' . $configName . ' could not be deleted because it did not exist</error>');
- return 1;
+ if (sizeof($configNames) > 1) {
+ if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) {
+ $output->writeln('<error>System config ' . implode(' => ', $configNames) . ' could not be deleted because it did not exist</error>');
+ return 1;
+ }
+
+ $value = $this->systemConfig->getValue($configName);
+
+ try {
+ $value = $this->removeSubValue(array_slice($configNames, 1), $value, $input->hasParameterOption('--error-if-not-exists'));
+ }
+ catch (\UnexpectedValueException $e) {
+ $output->writeln('<error>System config ' . implode(' => ', $configNames) . ' could not be deleted because it did not exist</error>');
+ return 1;
+ }
+
+ $this->systemConfig->setValue($configName, $value);
+ $output->writeln('<info>System config value ' . implode(' => ', $configNames) . ' deleted</info>');
+ return 0;
+ } else {
+ if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) {
+ $output->writeln('<error>System config ' . $configName . ' could not be deleted because it did not exist</error>');
+ return 1;
+ }
+
+ $this->systemConfig->deleteValue($configName);
+ $output->writeln('<info>System config value ' . $configName . ' deleted</info>');
+ return 0;
+ }
+ }
+
+ protected function removeSubValue($keys, $currentValue, $throwError) {
+ $nextKey = array_shift($keys);
+
+ if (is_array($currentValue)) {
+ if (isset($currentValue[$nextKey])) {
+ if (empty($keys)) {
+ unset($currentValue[$nextKey]);
+ } else {
+ $currentValue[$nextKey] = $this->removeSubValue($keys, $currentValue[$nextKey], $throwError);
+ }
+ } else if ($throwError) {
+ throw new \UnexpectedValueException('Config parameter does not exist');
+ }
+ } else if ($throwError) {
+ throw new \UnexpectedValueException('Config parameter does not exist');
}
- $this->systemConfig->deleteValue($configName);
- $output->writeln('<info>System config value ' . $configName . ' deleted</info>');
- return 0;
+ return $currentValue;
}
}
diff --git a/core/command/config/system/setconfig.php b/core/command/config/system/setconfig.php
index f05b8d6ead3..45ba01e9284 100644
--- a/core/command/config/system/setconfig.php
+++ b/core/command/config/system/setconfig.php
@@ -79,7 +79,7 @@ class SetConfig extends Base {
$configValue = $this->castValue($input->getOption('value'), $input->getOption('type'));
$updateOnly = $input->getOption('update-only');
- if (count($configNames) > 1) {
+ if (sizeof($configNames) > 1) {
$existingValue = $this->systemConfig->getValue($configName);
$newValue = $this->mergeArrayValue(