@@ -27,7 +27,7 @@ |
||
| 27 | 27 | |
| 28 | 28 | class WebCron extends Base { |
| 29 | 29 | |
| 30 | - protected function getMode() { |
|
| 31 | - return 'webcron'; |
|
| 32 | - } |
|
| 30 | + protected function getMode() { |
|
| 31 | + return 'webcron'; |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -39,39 +39,39 @@ |
||
| 39 | 39 | abstract class Base extends Command { |
| 40 | 40 | |
| 41 | 41 | |
| 42 | - abstract protected function getMode(); |
|
| 42 | + abstract protected function getMode(); |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @var \OCP\IConfig |
|
| 46 | - */ |
|
| 47 | - protected $config; |
|
| 44 | + /** |
|
| 45 | + * @var \OCP\IConfig |
|
| 46 | + */ |
|
| 47 | + protected $config; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @param \OCP\IConfig $config |
|
| 51 | - */ |
|
| 52 | - public function __construct(IConfig $config) { |
|
| 53 | - $this->config = $config; |
|
| 54 | - parent::__construct(); |
|
| 55 | - } |
|
| 49 | + /** |
|
| 50 | + * @param \OCP\IConfig $config |
|
| 51 | + */ |
|
| 52 | + public function __construct(IConfig $config) { |
|
| 53 | + $this->config = $config; |
|
| 54 | + parent::__construct(); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - protected function configure() { |
|
| 58 | - $mode = $this->getMode(); |
|
| 59 | - $this |
|
| 60 | - ->setName("background:$mode") |
|
| 61 | - ->setDescription("Use $mode to run background jobs"); |
|
| 62 | - } |
|
| 57 | + protected function configure() { |
|
| 58 | + $mode = $this->getMode(); |
|
| 59 | + $this |
|
| 60 | + ->setName("background:$mode") |
|
| 61 | + ->setDescription("Use $mode to run background jobs"); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Executing this command will set the background job mode for owncloud. |
|
| 66 | - * The mode to set is specified by the concrete sub class by implementing the |
|
| 67 | - * getMode() function. |
|
| 68 | - * |
|
| 69 | - * @param InputInterface $input |
|
| 70 | - * @param OutputInterface $output |
|
| 71 | - */ |
|
| 72 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 73 | - $mode = $this->getMode(); |
|
| 74 | - $this->config->setAppValue( 'core', 'backgroundjobs_mode', $mode ); |
|
| 75 | - $output->writeln("Set mode for background jobs to '$mode'"); |
|
| 76 | - } |
|
| 64 | + /** |
|
| 65 | + * Executing this command will set the background job mode for owncloud. |
|
| 66 | + * The mode to set is specified by the concrete sub class by implementing the |
|
| 67 | + * getMode() function. |
|
| 68 | + * |
|
| 69 | + * @param InputInterface $input |
|
| 70 | + * @param OutputInterface $output |
|
| 71 | + */ |
|
| 72 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 73 | + $mode = $this->getMode(); |
|
| 74 | + $this->config->setAppValue( 'core', 'backgroundjobs_mode', $mode ); |
|
| 75 | + $output->writeln("Set mode for background jobs to '$mode'"); |
|
| 76 | + } |
|
| 77 | 77 | } |
@@ -71,7 +71,7 @@ |
||
| 71 | 71 | */ |
| 72 | 72 | protected function execute(InputInterface $input, OutputInterface $output) { |
| 73 | 73 | $mode = $this->getMode(); |
| 74 | - $this->config->setAppValue( 'core', 'backgroundjobs_mode', $mode ); |
|
| 74 | + $this->config->setAppValue('core', 'backgroundjobs_mode', $mode); |
|
| 75 | 75 | $output->writeln("Set mode for background jobs to '$mode'"); |
| 76 | 76 | } |
| 77 | 77 | } |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | |
| 28 | 28 | class Cron extends Base { |
| 29 | 29 | |
| 30 | - protected function getMode() { |
|
| 31 | - return 'cron'; |
|
| 32 | - } |
|
| 30 | + protected function getMode() { |
|
| 31 | + return 'cron'; |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | |
| 28 | 28 | class Ajax extends Base { |
| 29 | 29 | |
| 30 | - protected function getMode() { |
|
| 31 | - return 'ajax'; |
|
| 32 | - } |
|
| 30 | + protected function getMode() { |
|
| 31 | + return 'ajax'; |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -32,127 +32,127 @@ |
||
| 32 | 32 | use Symfony\Component\Console\Output\OutputInterface; |
| 33 | 33 | |
| 34 | 34 | class ListConfigs extends Base { |
| 35 | - protected $defaultOutputFormat = self::OUTPUT_FORMAT_JSON_PRETTY; |
|
| 36 | - |
|
| 37 | - /** * @var SystemConfig */ |
|
| 38 | - protected $systemConfig; |
|
| 39 | - |
|
| 40 | - /** @var IAppConfig */ |
|
| 41 | - protected $appConfig; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @param SystemConfig $systemConfig |
|
| 45 | - * @param IAppConfig $appConfig |
|
| 46 | - */ |
|
| 47 | - public function __construct(SystemConfig $systemConfig, IAppConfig $appConfig) { |
|
| 48 | - parent::__construct(); |
|
| 49 | - $this->systemConfig = $systemConfig; |
|
| 50 | - $this->appConfig = $appConfig; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - protected function configure() { |
|
| 54 | - parent::configure(); |
|
| 55 | - |
|
| 56 | - $this |
|
| 57 | - ->setName('config:list') |
|
| 58 | - ->setDescription('List all configs') |
|
| 59 | - ->addArgument( |
|
| 60 | - 'app', |
|
| 61 | - InputArgument::OPTIONAL, |
|
| 62 | - 'Name of the app ("system" to get the config.php values, "all" for all apps and system)', |
|
| 63 | - 'all' |
|
| 64 | - ) |
|
| 65 | - ->addOption( |
|
| 66 | - 'private', |
|
| 67 | - null, |
|
| 68 | - InputOption::VALUE_NONE, |
|
| 69 | - 'Use this option when you want to include sensitive configs like passwords, salts, ...' |
|
| 70 | - ) |
|
| 71 | - ; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 75 | - $app = $input->getArgument('app'); |
|
| 76 | - $noSensitiveValues = !$input->getOption('private'); |
|
| 77 | - |
|
| 78 | - switch ($app) { |
|
| 79 | - case 'system': |
|
| 80 | - $configs = [ |
|
| 81 | - 'system' => $this->getSystemConfigs($noSensitiveValues), |
|
| 82 | - ]; |
|
| 83 | - break; |
|
| 84 | - |
|
| 85 | - case 'all': |
|
| 86 | - $apps = $this->appConfig->getApps(); |
|
| 87 | - $configs = [ |
|
| 88 | - 'system' => $this->getSystemConfigs($noSensitiveValues), |
|
| 89 | - 'apps' => [], |
|
| 90 | - ]; |
|
| 91 | - foreach ($apps as $appName) { |
|
| 92 | - $configs['apps'][$appName] = $this->getAppConfigs($appName, $noSensitiveValues); |
|
| 93 | - } |
|
| 94 | - break; |
|
| 95 | - |
|
| 96 | - default: |
|
| 97 | - $configs = [ |
|
| 98 | - 'apps' => [ |
|
| 99 | - $app => $this->getAppConfigs($app, $noSensitiveValues), |
|
| 100 | - ], |
|
| 101 | - ]; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $this->writeArrayInOutputFormat($input, $output, $configs); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Get the system configs |
|
| 109 | - * |
|
| 110 | - * @param bool $noSensitiveValues |
|
| 111 | - * @return array |
|
| 112 | - */ |
|
| 113 | - protected function getSystemConfigs($noSensitiveValues) { |
|
| 114 | - $keys = $this->systemConfig->getKeys(); |
|
| 115 | - |
|
| 116 | - $configs = []; |
|
| 117 | - foreach ($keys as $key) { |
|
| 118 | - if ($noSensitiveValues) { |
|
| 119 | - $value = $this->systemConfig->getFilteredValue($key, serialize(null)); |
|
| 120 | - } else { |
|
| 121 | - $value = $this->systemConfig->getValue($key, serialize(null)); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - if ($value !== 'N;') { |
|
| 125 | - $configs[$key] = $value; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - return $configs; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Get the app configs |
|
| 134 | - * |
|
| 135 | - * @param string $app |
|
| 136 | - * @param bool $noSensitiveValues |
|
| 137 | - * @return array |
|
| 138 | - */ |
|
| 139 | - protected function getAppConfigs($app, $noSensitiveValues) { |
|
| 140 | - if ($noSensitiveValues) { |
|
| 141 | - return $this->appConfig->getFilteredValues($app, false); |
|
| 142 | - } else { |
|
| 143 | - return $this->appConfig->getValues($app, false); |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @param string $argumentName |
|
| 149 | - * @param CompletionContext $context |
|
| 150 | - * @return string[] |
|
| 151 | - */ |
|
| 152 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
| 153 | - if ($argumentName === 'app') { |
|
| 154 | - return array_merge(['all', 'system'], \OC_App::getAllApps()); |
|
| 155 | - } |
|
| 156 | - return []; |
|
| 157 | - } |
|
| 35 | + protected $defaultOutputFormat = self::OUTPUT_FORMAT_JSON_PRETTY; |
|
| 36 | + |
|
| 37 | + /** * @var SystemConfig */ |
|
| 38 | + protected $systemConfig; |
|
| 39 | + |
|
| 40 | + /** @var IAppConfig */ |
|
| 41 | + protected $appConfig; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @param SystemConfig $systemConfig |
|
| 45 | + * @param IAppConfig $appConfig |
|
| 46 | + */ |
|
| 47 | + public function __construct(SystemConfig $systemConfig, IAppConfig $appConfig) { |
|
| 48 | + parent::__construct(); |
|
| 49 | + $this->systemConfig = $systemConfig; |
|
| 50 | + $this->appConfig = $appConfig; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + protected function configure() { |
|
| 54 | + parent::configure(); |
|
| 55 | + |
|
| 56 | + $this |
|
| 57 | + ->setName('config:list') |
|
| 58 | + ->setDescription('List all configs') |
|
| 59 | + ->addArgument( |
|
| 60 | + 'app', |
|
| 61 | + InputArgument::OPTIONAL, |
|
| 62 | + 'Name of the app ("system" to get the config.php values, "all" for all apps and system)', |
|
| 63 | + 'all' |
|
| 64 | + ) |
|
| 65 | + ->addOption( |
|
| 66 | + 'private', |
|
| 67 | + null, |
|
| 68 | + InputOption::VALUE_NONE, |
|
| 69 | + 'Use this option when you want to include sensitive configs like passwords, salts, ...' |
|
| 70 | + ) |
|
| 71 | + ; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 75 | + $app = $input->getArgument('app'); |
|
| 76 | + $noSensitiveValues = !$input->getOption('private'); |
|
| 77 | + |
|
| 78 | + switch ($app) { |
|
| 79 | + case 'system': |
|
| 80 | + $configs = [ |
|
| 81 | + 'system' => $this->getSystemConfigs($noSensitiveValues), |
|
| 82 | + ]; |
|
| 83 | + break; |
|
| 84 | + |
|
| 85 | + case 'all': |
|
| 86 | + $apps = $this->appConfig->getApps(); |
|
| 87 | + $configs = [ |
|
| 88 | + 'system' => $this->getSystemConfigs($noSensitiveValues), |
|
| 89 | + 'apps' => [], |
|
| 90 | + ]; |
|
| 91 | + foreach ($apps as $appName) { |
|
| 92 | + $configs['apps'][$appName] = $this->getAppConfigs($appName, $noSensitiveValues); |
|
| 93 | + } |
|
| 94 | + break; |
|
| 95 | + |
|
| 96 | + default: |
|
| 97 | + $configs = [ |
|
| 98 | + 'apps' => [ |
|
| 99 | + $app => $this->getAppConfigs($app, $noSensitiveValues), |
|
| 100 | + ], |
|
| 101 | + ]; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $this->writeArrayInOutputFormat($input, $output, $configs); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Get the system configs |
|
| 109 | + * |
|
| 110 | + * @param bool $noSensitiveValues |
|
| 111 | + * @return array |
|
| 112 | + */ |
|
| 113 | + protected function getSystemConfigs($noSensitiveValues) { |
|
| 114 | + $keys = $this->systemConfig->getKeys(); |
|
| 115 | + |
|
| 116 | + $configs = []; |
|
| 117 | + foreach ($keys as $key) { |
|
| 118 | + if ($noSensitiveValues) { |
|
| 119 | + $value = $this->systemConfig->getFilteredValue($key, serialize(null)); |
|
| 120 | + } else { |
|
| 121 | + $value = $this->systemConfig->getValue($key, serialize(null)); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + if ($value !== 'N;') { |
|
| 125 | + $configs[$key] = $value; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + return $configs; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Get the app configs |
|
| 134 | + * |
|
| 135 | + * @param string $app |
|
| 136 | + * @param bool $noSensitiveValues |
|
| 137 | + * @return array |
|
| 138 | + */ |
|
| 139 | + protected function getAppConfigs($app, $noSensitiveValues) { |
|
| 140 | + if ($noSensitiveValues) { |
|
| 141 | + return $this->appConfig->getFilteredValues($app, false); |
|
| 142 | + } else { |
|
| 143 | + return $this->appConfig->getValues($app, false); |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @param string $argumentName |
|
| 149 | + * @param CompletionContext $context |
|
| 150 | + * @return string[] |
|
| 151 | + */ |
|
| 152 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
| 153 | + if ($argumentName === 'app') { |
|
| 154 | + return array_merge(['all', 'system'], \OC_App::getAllApps()); |
|
| 155 | + } |
|
| 156 | + return []; |
|
| 157 | + } |
|
| 158 | 158 | } |
@@ -74,8 +74,7 @@ |
||
| 74 | 74 | |
| 75 | 75 | try { |
| 76 | 76 | $value = $this->removeSubValue(array_slice($configNames, 1), $value, $input->hasParameterOption('--error-if-not-exists')); |
| 77 | - } |
|
| 78 | - catch (\UnexpectedValueException $e) { |
|
| 77 | + } catch (\UnexpectedValueException $e) { |
|
| 79 | 78 | $output->writeln('<error>System config ' . implode(' => ', $configNames) . ' could not be deleted because it did not exist</error>'); |
| 80 | 79 | return 1; |
| 81 | 80 | } |
@@ -29,89 +29,89 @@ |
||
| 29 | 29 | use Symfony\Component\Console\Output\OutputInterface; |
| 30 | 30 | |
| 31 | 31 | class DeleteConfig extends Base { |
| 32 | - /** * @var SystemConfig */ |
|
| 33 | - protected $systemConfig; |
|
| 32 | + /** * @var SystemConfig */ |
|
| 33 | + protected $systemConfig; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param SystemConfig $systemConfig |
|
| 37 | - */ |
|
| 38 | - public function __construct(SystemConfig $systemConfig) { |
|
| 39 | - parent::__construct(); |
|
| 40 | - $this->systemConfig = $systemConfig; |
|
| 41 | - } |
|
| 35 | + /** |
|
| 36 | + * @param SystemConfig $systemConfig |
|
| 37 | + */ |
|
| 38 | + public function __construct(SystemConfig $systemConfig) { |
|
| 39 | + parent::__construct(); |
|
| 40 | + $this->systemConfig = $systemConfig; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - protected function configure() { |
|
| 44 | - parent::configure(); |
|
| 43 | + protected function configure() { |
|
| 44 | + parent::configure(); |
|
| 45 | 45 | |
| 46 | - $this |
|
| 47 | - ->setName('config:system:delete') |
|
| 48 | - ->setDescription('Delete a system config value') |
|
| 49 | - ->addArgument( |
|
| 50 | - 'name', |
|
| 51 | - InputArgument::REQUIRED | InputArgument::IS_ARRAY, |
|
| 52 | - 'Name of the config to delete, specify multiple for array parameter' |
|
| 53 | - ) |
|
| 54 | - ->addOption( |
|
| 55 | - 'error-if-not-exists', |
|
| 56 | - null, |
|
| 57 | - InputOption::VALUE_NONE, |
|
| 58 | - 'Checks whether the config exists before deleting it' |
|
| 59 | - ) |
|
| 60 | - ; |
|
| 61 | - } |
|
| 46 | + $this |
|
| 47 | + ->setName('config:system:delete') |
|
| 48 | + ->setDescription('Delete a system config value') |
|
| 49 | + ->addArgument( |
|
| 50 | + 'name', |
|
| 51 | + InputArgument::REQUIRED | InputArgument::IS_ARRAY, |
|
| 52 | + 'Name of the config to delete, specify multiple for array parameter' |
|
| 53 | + ) |
|
| 54 | + ->addOption( |
|
| 55 | + 'error-if-not-exists', |
|
| 56 | + null, |
|
| 57 | + InputOption::VALUE_NONE, |
|
| 58 | + 'Checks whether the config exists before deleting it' |
|
| 59 | + ) |
|
| 60 | + ; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 64 | - $configNames = $input->getArgument('name'); |
|
| 65 | - $configName = $configNames[0]; |
|
| 63 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 64 | + $configNames = $input->getArgument('name'); |
|
| 65 | + $configName = $configNames[0]; |
|
| 66 | 66 | |
| 67 | - if (count($configNames) > 1) { |
|
| 68 | - if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) { |
|
| 69 | - $output->writeln('<error>System config ' . implode(' => ', $configNames) . ' could not be deleted because it did not exist</error>'); |
|
| 70 | - return 1; |
|
| 71 | - } |
|
| 67 | + if (count($configNames) > 1) { |
|
| 68 | + if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) { |
|
| 69 | + $output->writeln('<error>System config ' . implode(' => ', $configNames) . ' could not be deleted because it did not exist</error>'); |
|
| 70 | + return 1; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - $value = $this->systemConfig->getValue($configName); |
|
| 73 | + $value = $this->systemConfig->getValue($configName); |
|
| 74 | 74 | |
| 75 | - try { |
|
| 76 | - $value = $this->removeSubValue(array_slice($configNames, 1), $value, $input->hasParameterOption('--error-if-not-exists')); |
|
| 77 | - } |
|
| 78 | - catch (\UnexpectedValueException $e) { |
|
| 79 | - $output->writeln('<error>System config ' . implode(' => ', $configNames) . ' could not be deleted because it did not exist</error>'); |
|
| 80 | - return 1; |
|
| 81 | - } |
|
| 75 | + try { |
|
| 76 | + $value = $this->removeSubValue(array_slice($configNames, 1), $value, $input->hasParameterOption('--error-if-not-exists')); |
|
| 77 | + } |
|
| 78 | + catch (\UnexpectedValueException $e) { |
|
| 79 | + $output->writeln('<error>System config ' . implode(' => ', $configNames) . ' could not be deleted because it did not exist</error>'); |
|
| 80 | + return 1; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - $this->systemConfig->setValue($configName, $value); |
|
| 84 | - $output->writeln('<info>System config value ' . implode(' => ', $configNames) . ' deleted</info>'); |
|
| 85 | - return 0; |
|
| 86 | - } else { |
|
| 87 | - if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) { |
|
| 88 | - $output->writeln('<error>System config ' . $configName . ' could not be deleted because it did not exist</error>'); |
|
| 89 | - return 1; |
|
| 90 | - } |
|
| 83 | + $this->systemConfig->setValue($configName, $value); |
|
| 84 | + $output->writeln('<info>System config value ' . implode(' => ', $configNames) . ' deleted</info>'); |
|
| 85 | + return 0; |
|
| 86 | + } else { |
|
| 87 | + if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) { |
|
| 88 | + $output->writeln('<error>System config ' . $configName . ' could not be deleted because it did not exist</error>'); |
|
| 89 | + return 1; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - $this->systemConfig->deleteValue($configName); |
|
| 93 | - $output->writeln('<info>System config value ' . $configName . ' deleted</info>'); |
|
| 94 | - return 0; |
|
| 95 | - } |
|
| 96 | - } |
|
| 92 | + $this->systemConfig->deleteValue($configName); |
|
| 93 | + $output->writeln('<info>System config value ' . $configName . ' deleted</info>'); |
|
| 94 | + return 0; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - protected function removeSubValue($keys, $currentValue, $throwError) { |
|
| 99 | - $nextKey = array_shift($keys); |
|
| 98 | + protected function removeSubValue($keys, $currentValue, $throwError) { |
|
| 99 | + $nextKey = array_shift($keys); |
|
| 100 | 100 | |
| 101 | - if (is_array($currentValue)) { |
|
| 102 | - if (isset($currentValue[$nextKey])) { |
|
| 103 | - if (empty($keys)) { |
|
| 104 | - unset($currentValue[$nextKey]); |
|
| 105 | - } else { |
|
| 106 | - $currentValue[$nextKey] = $this->removeSubValue($keys, $currentValue[$nextKey], $throwError); |
|
| 107 | - } |
|
| 108 | - } else if ($throwError) { |
|
| 109 | - throw new \UnexpectedValueException('Config parameter does not exist'); |
|
| 110 | - } |
|
| 111 | - } else if ($throwError) { |
|
| 112 | - throw new \UnexpectedValueException('Config parameter does not exist'); |
|
| 113 | - } |
|
| 101 | + if (is_array($currentValue)) { |
|
| 102 | + if (isset($currentValue[$nextKey])) { |
|
| 103 | + if (empty($keys)) { |
|
| 104 | + unset($currentValue[$nextKey]); |
|
| 105 | + } else { |
|
| 106 | + $currentValue[$nextKey] = $this->removeSubValue($keys, $currentValue[$nextKey], $throwError); |
|
| 107 | + } |
|
| 108 | + } else if ($throwError) { |
|
| 109 | + throw new \UnexpectedValueException('Config parameter does not exist'); |
|
| 110 | + } |
|
| 111 | + } else if ($throwError) { |
|
| 112 | + throw new \UnexpectedValueException('Config parameter does not exist'); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - return $currentValue; |
|
| 116 | - } |
|
| 115 | + return $currentValue; |
|
| 116 | + } |
|
| 117 | 117 | } |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | if (count($configNames) > 1) { |
| 68 | 68 | if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) { |
| 69 | - $output->writeln('<error>System config ' . implode(' => ', $configNames) . ' could not be deleted because it did not exist</error>'); |
|
| 69 | + $output->writeln('<error>System config '.implode(' => ', $configNames).' could not be deleted because it did not exist</error>'); |
|
| 70 | 70 | return 1; |
| 71 | 71 | } |
| 72 | 72 | |
@@ -76,21 +76,21 @@ discard block |
||
| 76 | 76 | $value = $this->removeSubValue(array_slice($configNames, 1), $value, $input->hasParameterOption('--error-if-not-exists')); |
| 77 | 77 | } |
| 78 | 78 | catch (\UnexpectedValueException $e) { |
| 79 | - $output->writeln('<error>System config ' . implode(' => ', $configNames) . ' could not be deleted because it did not exist</error>'); |
|
| 79 | + $output->writeln('<error>System config '.implode(' => ', $configNames).' could not be deleted because it did not exist</error>'); |
|
| 80 | 80 | return 1; |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | $this->systemConfig->setValue($configName, $value); |
| 84 | - $output->writeln('<info>System config value ' . implode(' => ', $configNames) . ' deleted</info>'); |
|
| 84 | + $output->writeln('<info>System config value '.implode(' => ', $configNames).' deleted</info>'); |
|
| 85 | 85 | return 0; |
| 86 | 86 | } else { |
| 87 | 87 | if ($input->hasParameterOption('--error-if-not-exists') && !in_array($configName, $this->systemConfig->getKeys())) { |
| 88 | - $output->writeln('<error>System config ' . $configName . ' could not be deleted because it did not exist</error>'); |
|
| 88 | + $output->writeln('<error>System config '.$configName.' could not be deleted because it did not exist</error>'); |
|
| 89 | 89 | return 1; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | $this->systemConfig->deleteValue($configName); |
| 93 | - $output->writeln('<info>System config value ' . $configName . ' deleted</info>'); |
|
| 93 | + $output->writeln('<info>System config value '.$configName.' deleted</info>'); |
|
| 94 | 94 | return 0; |
| 95 | 95 | } |
| 96 | 96 | } |
@@ -26,53 +26,53 @@ |
||
| 26 | 26 | |
| 27 | 27 | abstract class Base extends \OC\Core\Command\Base { |
| 28 | 28 | |
| 29 | - /** @var SystemConfig */ |
|
| 30 | - protected $systemConfig; |
|
| 29 | + /** @var SystemConfig */ |
|
| 30 | + protected $systemConfig; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @param string $argumentName |
|
| 34 | - * @param CompletionContext $context |
|
| 35 | - * @return string[] |
|
| 36 | - */ |
|
| 37 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
| 38 | - if ($argumentName === 'name') { |
|
| 39 | - $words = $this->getPreviousNames($context, $context->getWordIndex()); |
|
| 40 | - if (empty($words)) { |
|
| 41 | - $completions = $this->systemConfig->getKeys(); |
|
| 42 | - } else { |
|
| 43 | - $key = array_shift($words); |
|
| 44 | - $value = $this->systemConfig->getValue($key); |
|
| 45 | - $completions = array_keys($value); |
|
| 32 | + /** |
|
| 33 | + * @param string $argumentName |
|
| 34 | + * @param CompletionContext $context |
|
| 35 | + * @return string[] |
|
| 36 | + */ |
|
| 37 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
| 38 | + if ($argumentName === 'name') { |
|
| 39 | + $words = $this->getPreviousNames($context, $context->getWordIndex()); |
|
| 40 | + if (empty($words)) { |
|
| 41 | + $completions = $this->systemConfig->getKeys(); |
|
| 42 | + } else { |
|
| 43 | + $key = array_shift($words); |
|
| 44 | + $value = $this->systemConfig->getValue($key); |
|
| 45 | + $completions = array_keys($value); |
|
| 46 | 46 | |
| 47 | - while (!empty($words) && is_array($value)) { |
|
| 48 | - $key = array_shift($words); |
|
| 49 | - if (!isset($value[$key]) || !is_array($value[$key])) { |
|
| 50 | - break; |
|
| 51 | - } |
|
| 47 | + while (!empty($words) && is_array($value)) { |
|
| 48 | + $key = array_shift($words); |
|
| 49 | + if (!isset($value[$key]) || !is_array($value[$key])) { |
|
| 50 | + break; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - $value = $value[$key]; |
|
| 54 | - $completions = array_keys($value); |
|
| 55 | - } |
|
| 56 | - } |
|
| 53 | + $value = $value[$key]; |
|
| 54 | + $completions = array_keys($value); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - return $completions; |
|
| 59 | - } |
|
| 60 | - return parent::completeArgumentValues($argumentName, $context); |
|
| 61 | - } |
|
| 58 | + return $completions; |
|
| 59 | + } |
|
| 60 | + return parent::completeArgumentValues($argumentName, $context); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @param CompletionContext $context |
|
| 65 | - * @param int $currentIndex |
|
| 66 | - * @return string[] |
|
| 67 | - */ |
|
| 68 | - protected function getPreviousNames(CompletionContext $context, $currentIndex) { |
|
| 69 | - $word = $context->getWordAtIndex($currentIndex - 1); |
|
| 70 | - if ($word === $this->getName() || $currentIndex <= 0) { |
|
| 71 | - return []; |
|
| 72 | - } |
|
| 63 | + /** |
|
| 64 | + * @param CompletionContext $context |
|
| 65 | + * @param int $currentIndex |
|
| 66 | + * @return string[] |
|
| 67 | + */ |
|
| 68 | + protected function getPreviousNames(CompletionContext $context, $currentIndex) { |
|
| 69 | + $word = $context->getWordAtIndex($currentIndex - 1); |
|
| 70 | + if ($word === $this->getName() || $currentIndex <= 0) { |
|
| 71 | + return []; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - $words = $this->getPreviousNames($context, $currentIndex - 1); |
|
| 75 | - $words[] = $word; |
|
| 76 | - return $words; |
|
| 77 | - } |
|
| 74 | + $words = $this->getPreviousNames($context, $currentIndex - 1); |
|
| 75 | + $words[] = $word; |
|
| 76 | + return $words; |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | $this->systemConfig->setValue($configName, $configValue['value']); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - $output->writeln('<info>System config value ' . implode(' => ', $configNames) . ' set to ' . $configValue['readable-value'] . '</info>'); |
|
| 100 | + $output->writeln('<info>System config value '.implode(' => ', $configNames).' set to '.$configValue['readable-value'].'</info>'); |
|
| 101 | 101 | return 0; |
| 102 | 102 | } |
| 103 | 103 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | } |
| 117 | 117 | return [ |
| 118 | 118 | 'value' => (int) $value, |
| 119 | - 'readable-value' => 'integer ' . (int) $value, |
|
| 119 | + 'readable-value' => 'integer '.(int) $value, |
|
| 120 | 120 | ]; |
| 121 | 121 | |
| 122 | 122 | case 'double': |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | } |
| 127 | 127 | return [ |
| 128 | 128 | 'value' => (double) $value, |
| 129 | - 'readable-value' => 'double ' . (double) $value, |
|
| 129 | + 'readable-value' => 'double '.(double) $value, |
|
| 130 | 130 | ]; |
| 131 | 131 | |
| 132 | 132 | case 'boolean': |
@@ -136,13 +136,13 @@ discard block |
||
| 136 | 136 | case 'true': |
| 137 | 137 | return [ |
| 138 | 138 | 'value' => true, |
| 139 | - 'readable-value' => 'boolean ' . $value, |
|
| 139 | + 'readable-value' => 'boolean '.$value, |
|
| 140 | 140 | ]; |
| 141 | 141 | |
| 142 | 142 | case 'false': |
| 143 | 143 | return [ |
| 144 | 144 | 'value' => false, |
| 145 | - 'readable-value' => 'boolean ' . $value, |
|
| 145 | + 'readable-value' => 'boolean '.$value, |
|
| 146 | 146 | ]; |
| 147 | 147 | |
| 148 | 148 | default: |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $value = (string) $value; |
| 160 | 160 | return [ |
| 161 | 161 | 'value' => $value, |
| 162 | - 'readable-value' => ($value === '') ? 'empty string' : 'string ' . $value, |
|
| 162 | + 'readable-value' => ($value === '') ? 'empty string' : 'string '.$value, |
|
| 163 | 163 | ]; |
| 164 | 164 | |
| 165 | 165 | default: |
@@ -31,180 +31,180 @@ |
||
| 31 | 31 | use Symfony\Component\Console\Output\OutputInterface; |
| 32 | 32 | |
| 33 | 33 | class SetConfig extends Base { |
| 34 | - /** * @var SystemConfig */ |
|
| 35 | - protected $systemConfig; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @param SystemConfig $systemConfig |
|
| 39 | - */ |
|
| 40 | - public function __construct(SystemConfig $systemConfig) { |
|
| 41 | - parent::__construct(); |
|
| 42 | - $this->systemConfig = $systemConfig; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - protected function configure() { |
|
| 46 | - parent::configure(); |
|
| 47 | - |
|
| 48 | - $this |
|
| 49 | - ->setName('config:system:set') |
|
| 50 | - ->setDescription('Set a system config value') |
|
| 51 | - ->addArgument( |
|
| 52 | - 'name', |
|
| 53 | - InputArgument::REQUIRED | InputArgument::IS_ARRAY, |
|
| 54 | - 'Name of the config parameter, specify multiple for array parameter' |
|
| 55 | - ) |
|
| 56 | - ->addOption( |
|
| 57 | - 'type', |
|
| 58 | - null, |
|
| 59 | - InputOption::VALUE_REQUIRED, |
|
| 60 | - 'Value type [string, integer, double, boolean]', |
|
| 61 | - 'string' |
|
| 62 | - ) |
|
| 63 | - ->addOption( |
|
| 64 | - 'value', |
|
| 65 | - null, |
|
| 66 | - InputOption::VALUE_REQUIRED, |
|
| 67 | - 'The new value of the config' |
|
| 68 | - ) |
|
| 69 | - ->addOption( |
|
| 70 | - 'update-only', |
|
| 71 | - null, |
|
| 72 | - InputOption::VALUE_NONE, |
|
| 73 | - 'Only updates the value, if it is not set before, it is not being added' |
|
| 74 | - ) |
|
| 75 | - ; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 79 | - $configNames = $input->getArgument('name'); |
|
| 80 | - $configName = $configNames[0]; |
|
| 81 | - $configValue = $this->castValue($input->getOption('value'), $input->getOption('type')); |
|
| 82 | - $updateOnly = $input->getOption('update-only'); |
|
| 83 | - |
|
| 84 | - if (count($configNames) > 1) { |
|
| 85 | - $existingValue = $this->systemConfig->getValue($configName); |
|
| 86 | - |
|
| 87 | - $newValue = $this->mergeArrayValue( |
|
| 88 | - array_slice($configNames, 1), $existingValue, $configValue['value'], $updateOnly |
|
| 89 | - ); |
|
| 90 | - |
|
| 91 | - $this->systemConfig->setValue($configName, $newValue); |
|
| 92 | - } else { |
|
| 93 | - if ($updateOnly && !in_array($configName, $this->systemConfig->getKeys(), true)) { |
|
| 94 | - throw new \UnexpectedValueException('Config parameter does not exist'); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $this->systemConfig->setValue($configName, $configValue['value']); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - $output->writeln('<info>System config value ' . implode(' => ', $configNames) . ' set to ' . $configValue['readable-value'] . '</info>'); |
|
| 101 | - return 0; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @param string $value |
|
| 106 | - * @param string $type |
|
| 107 | - * @return mixed |
|
| 108 | - * @throws \InvalidArgumentException |
|
| 109 | - */ |
|
| 110 | - protected function castValue($value, $type) { |
|
| 111 | - switch ($type) { |
|
| 112 | - case 'integer': |
|
| 113 | - case 'int': |
|
| 114 | - if (!is_numeric($value)) { |
|
| 115 | - throw new \InvalidArgumentException('Non-numeric value specified'); |
|
| 116 | - } |
|
| 117 | - return [ |
|
| 118 | - 'value' => (int) $value, |
|
| 119 | - 'readable-value' => 'integer ' . (int) $value, |
|
| 120 | - ]; |
|
| 121 | - |
|
| 122 | - case 'double': |
|
| 123 | - case 'float': |
|
| 124 | - if (!is_numeric($value)) { |
|
| 125 | - throw new \InvalidArgumentException('Non-numeric value specified'); |
|
| 126 | - } |
|
| 127 | - return [ |
|
| 128 | - 'value' => (double) $value, |
|
| 129 | - 'readable-value' => 'double ' . (double) $value, |
|
| 130 | - ]; |
|
| 131 | - |
|
| 132 | - case 'boolean': |
|
| 133 | - case 'bool': |
|
| 134 | - $value = strtolower($value); |
|
| 135 | - switch ($value) { |
|
| 136 | - case 'true': |
|
| 137 | - return [ |
|
| 138 | - 'value' => true, |
|
| 139 | - 'readable-value' => 'boolean ' . $value, |
|
| 140 | - ]; |
|
| 141 | - |
|
| 142 | - case 'false': |
|
| 143 | - return [ |
|
| 144 | - 'value' => false, |
|
| 145 | - 'readable-value' => 'boolean ' . $value, |
|
| 146 | - ]; |
|
| 147 | - |
|
| 148 | - default: |
|
| 149 | - throw new \InvalidArgumentException('Unable to parse value as boolean'); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - case 'null': |
|
| 153 | - return [ |
|
| 154 | - 'value' => null, |
|
| 155 | - 'readable-value' => 'null', |
|
| 156 | - ]; |
|
| 157 | - |
|
| 158 | - case 'string': |
|
| 159 | - $value = (string) $value; |
|
| 160 | - return [ |
|
| 161 | - 'value' => $value, |
|
| 162 | - 'readable-value' => ($value === '') ? 'empty string' : 'string ' . $value, |
|
| 163 | - ]; |
|
| 164 | - |
|
| 165 | - default: |
|
| 166 | - throw new \InvalidArgumentException('Invalid type'); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @param array $configNames |
|
| 172 | - * @param mixed $existingValues |
|
| 173 | - * @param mixed $value |
|
| 174 | - * @param bool $updateOnly |
|
| 175 | - * @return array merged value |
|
| 176 | - * @throws \UnexpectedValueException |
|
| 177 | - */ |
|
| 178 | - protected function mergeArrayValue(array $configNames, $existingValues, $value, $updateOnly) { |
|
| 179 | - $configName = array_shift($configNames); |
|
| 180 | - if (!is_array($existingValues)) { |
|
| 181 | - $existingValues = []; |
|
| 182 | - } |
|
| 183 | - if (!empty($configNames)) { |
|
| 184 | - if (isset($existingValues[$configName])) { |
|
| 185 | - $existingValue = $existingValues[$configName]; |
|
| 186 | - } else { |
|
| 187 | - $existingValue = []; |
|
| 188 | - } |
|
| 189 | - $existingValues[$configName] = $this->mergeArrayValue($configNames, $existingValue, $value, $updateOnly); |
|
| 190 | - } else { |
|
| 191 | - if (!isset($existingValues[$configName]) && $updateOnly) { |
|
| 192 | - throw new \UnexpectedValueException('Config parameter does not exist'); |
|
| 193 | - } |
|
| 194 | - $existingValues[$configName] = $value; |
|
| 195 | - } |
|
| 196 | - return $existingValues; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * @param string $optionName |
|
| 201 | - * @param CompletionContext $context |
|
| 202 | - * @return string[] |
|
| 203 | - */ |
|
| 204 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
| 205 | - if ($optionName === 'type') { |
|
| 206 | - return ['string', 'integer', 'double', 'boolean']; |
|
| 207 | - } |
|
| 208 | - return parent::completeOptionValues($optionName, $context); |
|
| 209 | - } |
|
| 34 | + /** * @var SystemConfig */ |
|
| 35 | + protected $systemConfig; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @param SystemConfig $systemConfig |
|
| 39 | + */ |
|
| 40 | + public function __construct(SystemConfig $systemConfig) { |
|
| 41 | + parent::__construct(); |
|
| 42 | + $this->systemConfig = $systemConfig; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + protected function configure() { |
|
| 46 | + parent::configure(); |
|
| 47 | + |
|
| 48 | + $this |
|
| 49 | + ->setName('config:system:set') |
|
| 50 | + ->setDescription('Set a system config value') |
|
| 51 | + ->addArgument( |
|
| 52 | + 'name', |
|
| 53 | + InputArgument::REQUIRED | InputArgument::IS_ARRAY, |
|
| 54 | + 'Name of the config parameter, specify multiple for array parameter' |
|
| 55 | + ) |
|
| 56 | + ->addOption( |
|
| 57 | + 'type', |
|
| 58 | + null, |
|
| 59 | + InputOption::VALUE_REQUIRED, |
|
| 60 | + 'Value type [string, integer, double, boolean]', |
|
| 61 | + 'string' |
|
| 62 | + ) |
|
| 63 | + ->addOption( |
|
| 64 | + 'value', |
|
| 65 | + null, |
|
| 66 | + InputOption::VALUE_REQUIRED, |
|
| 67 | + 'The new value of the config' |
|
| 68 | + ) |
|
| 69 | + ->addOption( |
|
| 70 | + 'update-only', |
|
| 71 | + null, |
|
| 72 | + InputOption::VALUE_NONE, |
|
| 73 | + 'Only updates the value, if it is not set before, it is not being added' |
|
| 74 | + ) |
|
| 75 | + ; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 79 | + $configNames = $input->getArgument('name'); |
|
| 80 | + $configName = $configNames[0]; |
|
| 81 | + $configValue = $this->castValue($input->getOption('value'), $input->getOption('type')); |
|
| 82 | + $updateOnly = $input->getOption('update-only'); |
|
| 83 | + |
|
| 84 | + if (count($configNames) > 1) { |
|
| 85 | + $existingValue = $this->systemConfig->getValue($configName); |
|
| 86 | + |
|
| 87 | + $newValue = $this->mergeArrayValue( |
|
| 88 | + array_slice($configNames, 1), $existingValue, $configValue['value'], $updateOnly |
|
| 89 | + ); |
|
| 90 | + |
|
| 91 | + $this->systemConfig->setValue($configName, $newValue); |
|
| 92 | + } else { |
|
| 93 | + if ($updateOnly && !in_array($configName, $this->systemConfig->getKeys(), true)) { |
|
| 94 | + throw new \UnexpectedValueException('Config parameter does not exist'); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $this->systemConfig->setValue($configName, $configValue['value']); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + $output->writeln('<info>System config value ' . implode(' => ', $configNames) . ' set to ' . $configValue['readable-value'] . '</info>'); |
|
| 101 | + return 0; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @param string $value |
|
| 106 | + * @param string $type |
|
| 107 | + * @return mixed |
|
| 108 | + * @throws \InvalidArgumentException |
|
| 109 | + */ |
|
| 110 | + protected function castValue($value, $type) { |
|
| 111 | + switch ($type) { |
|
| 112 | + case 'integer': |
|
| 113 | + case 'int': |
|
| 114 | + if (!is_numeric($value)) { |
|
| 115 | + throw new \InvalidArgumentException('Non-numeric value specified'); |
|
| 116 | + } |
|
| 117 | + return [ |
|
| 118 | + 'value' => (int) $value, |
|
| 119 | + 'readable-value' => 'integer ' . (int) $value, |
|
| 120 | + ]; |
|
| 121 | + |
|
| 122 | + case 'double': |
|
| 123 | + case 'float': |
|
| 124 | + if (!is_numeric($value)) { |
|
| 125 | + throw new \InvalidArgumentException('Non-numeric value specified'); |
|
| 126 | + } |
|
| 127 | + return [ |
|
| 128 | + 'value' => (double) $value, |
|
| 129 | + 'readable-value' => 'double ' . (double) $value, |
|
| 130 | + ]; |
|
| 131 | + |
|
| 132 | + case 'boolean': |
|
| 133 | + case 'bool': |
|
| 134 | + $value = strtolower($value); |
|
| 135 | + switch ($value) { |
|
| 136 | + case 'true': |
|
| 137 | + return [ |
|
| 138 | + 'value' => true, |
|
| 139 | + 'readable-value' => 'boolean ' . $value, |
|
| 140 | + ]; |
|
| 141 | + |
|
| 142 | + case 'false': |
|
| 143 | + return [ |
|
| 144 | + 'value' => false, |
|
| 145 | + 'readable-value' => 'boolean ' . $value, |
|
| 146 | + ]; |
|
| 147 | + |
|
| 148 | + default: |
|
| 149 | + throw new \InvalidArgumentException('Unable to parse value as boolean'); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + case 'null': |
|
| 153 | + return [ |
|
| 154 | + 'value' => null, |
|
| 155 | + 'readable-value' => 'null', |
|
| 156 | + ]; |
|
| 157 | + |
|
| 158 | + case 'string': |
|
| 159 | + $value = (string) $value; |
|
| 160 | + return [ |
|
| 161 | + 'value' => $value, |
|
| 162 | + 'readable-value' => ($value === '') ? 'empty string' : 'string ' . $value, |
|
| 163 | + ]; |
|
| 164 | + |
|
| 165 | + default: |
|
| 166 | + throw new \InvalidArgumentException('Invalid type'); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @param array $configNames |
|
| 172 | + * @param mixed $existingValues |
|
| 173 | + * @param mixed $value |
|
| 174 | + * @param bool $updateOnly |
|
| 175 | + * @return array merged value |
|
| 176 | + * @throws \UnexpectedValueException |
|
| 177 | + */ |
|
| 178 | + protected function mergeArrayValue(array $configNames, $existingValues, $value, $updateOnly) { |
|
| 179 | + $configName = array_shift($configNames); |
|
| 180 | + if (!is_array($existingValues)) { |
|
| 181 | + $existingValues = []; |
|
| 182 | + } |
|
| 183 | + if (!empty($configNames)) { |
|
| 184 | + if (isset($existingValues[$configName])) { |
|
| 185 | + $existingValue = $existingValues[$configName]; |
|
| 186 | + } else { |
|
| 187 | + $existingValue = []; |
|
| 188 | + } |
|
| 189 | + $existingValues[$configName] = $this->mergeArrayValue($configNames, $existingValue, $value, $updateOnly); |
|
| 190 | + } else { |
|
| 191 | + if (!isset($existingValues[$configName]) && $updateOnly) { |
|
| 192 | + throw new \UnexpectedValueException('Config parameter does not exist'); |
|
| 193 | + } |
|
| 194 | + $existingValues[$configName] = $value; |
|
| 195 | + } |
|
| 196 | + return $existingValues; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * @param string $optionName |
|
| 201 | + * @param CompletionContext $context |
|
| 202 | + * @return string[] |
|
| 203 | + */ |
|
| 204 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
| 205 | + if ($optionName === 'type') { |
|
| 206 | + return ['string', 'integer', 'double', 'boolean']; |
|
| 207 | + } |
|
| 208 | + return parent::completeOptionValues($optionName, $context); |
|
| 209 | + } |
|
| 210 | 210 | } |
@@ -29,72 +29,72 @@ |
||
| 29 | 29 | use Symfony\Component\Console\Output\OutputInterface; |
| 30 | 30 | |
| 31 | 31 | class GetConfig extends Base { |
| 32 | - /** * @var SystemConfig */ |
|
| 33 | - protected $systemConfig; |
|
| 32 | + /** * @var SystemConfig */ |
|
| 33 | + protected $systemConfig; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param SystemConfig $systemConfig |
|
| 37 | - */ |
|
| 38 | - public function __construct(SystemConfig $systemConfig) { |
|
| 39 | - parent::__construct(); |
|
| 40 | - $this->systemConfig = $systemConfig; |
|
| 41 | - } |
|
| 35 | + /** |
|
| 36 | + * @param SystemConfig $systemConfig |
|
| 37 | + */ |
|
| 38 | + public function __construct(SystemConfig $systemConfig) { |
|
| 39 | + parent::__construct(); |
|
| 40 | + $this->systemConfig = $systemConfig; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - protected function configure() { |
|
| 44 | - parent::configure(); |
|
| 43 | + protected function configure() { |
|
| 44 | + parent::configure(); |
|
| 45 | 45 | |
| 46 | - $this |
|
| 47 | - ->setName('config:system:get') |
|
| 48 | - ->setDescription('Get a system config value') |
|
| 49 | - ->addArgument( |
|
| 50 | - 'name', |
|
| 51 | - InputArgument::REQUIRED | InputArgument::IS_ARRAY, |
|
| 52 | - 'Name of the config to get, specify multiple for array parameter' |
|
| 53 | - ) |
|
| 54 | - ->addOption( |
|
| 55 | - 'default-value', |
|
| 56 | - null, |
|
| 57 | - InputOption::VALUE_OPTIONAL, |
|
| 58 | - 'If no default value is set and the config does not exist, the command will exit with 1' |
|
| 59 | - ) |
|
| 60 | - ; |
|
| 61 | - } |
|
| 46 | + $this |
|
| 47 | + ->setName('config:system:get') |
|
| 48 | + ->setDescription('Get a system config value') |
|
| 49 | + ->addArgument( |
|
| 50 | + 'name', |
|
| 51 | + InputArgument::REQUIRED | InputArgument::IS_ARRAY, |
|
| 52 | + 'Name of the config to get, specify multiple for array parameter' |
|
| 53 | + ) |
|
| 54 | + ->addOption( |
|
| 55 | + 'default-value', |
|
| 56 | + null, |
|
| 57 | + InputOption::VALUE_OPTIONAL, |
|
| 58 | + 'If no default value is set and the config does not exist, the command will exit with 1' |
|
| 59 | + ) |
|
| 60 | + ; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Executes the current command. |
|
| 65 | - * |
|
| 66 | - * @param InputInterface $input An InputInterface instance |
|
| 67 | - * @param OutputInterface $output An OutputInterface instance |
|
| 68 | - * @return null|int null or 0 if everything went fine, or an error code |
|
| 69 | - */ |
|
| 70 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 71 | - $configNames = $input->getArgument('name'); |
|
| 72 | - $configName = array_shift($configNames); |
|
| 73 | - $defaultValue = $input->getOption('default-value'); |
|
| 63 | + /** |
|
| 64 | + * Executes the current command. |
|
| 65 | + * |
|
| 66 | + * @param InputInterface $input An InputInterface instance |
|
| 67 | + * @param OutputInterface $output An OutputInterface instance |
|
| 68 | + * @return null|int null or 0 if everything went fine, or an error code |
|
| 69 | + */ |
|
| 70 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 71 | + $configNames = $input->getArgument('name'); |
|
| 72 | + $configName = array_shift($configNames); |
|
| 73 | + $defaultValue = $input->getOption('default-value'); |
|
| 74 | 74 | |
| 75 | - if (!in_array($configName, $this->systemConfig->getKeys()) && !$input->hasParameterOption('--default-value')) { |
|
| 76 | - return 1; |
|
| 77 | - } |
|
| 75 | + if (!in_array($configName, $this->systemConfig->getKeys()) && !$input->hasParameterOption('--default-value')) { |
|
| 76 | + return 1; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - if (!in_array($configName, $this->systemConfig->getKeys())) { |
|
| 80 | - $configValue = $defaultValue; |
|
| 81 | - } else { |
|
| 82 | - $configValue = $this->systemConfig->getValue($configName); |
|
| 83 | - if (!empty($configNames)) { |
|
| 84 | - foreach ($configNames as $configName) { |
|
| 85 | - if (isset($configValue[$configName])) { |
|
| 86 | - $configValue = $configValue[$configName]; |
|
| 87 | - } else if (!$input->hasParameterOption('--default-value')) { |
|
| 88 | - return 1; |
|
| 89 | - } else { |
|
| 90 | - $configValue = $defaultValue; |
|
| 91 | - break; |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - } |
|
| 79 | + if (!in_array($configName, $this->systemConfig->getKeys())) { |
|
| 80 | + $configValue = $defaultValue; |
|
| 81 | + } else { |
|
| 82 | + $configValue = $this->systemConfig->getValue($configName); |
|
| 83 | + if (!empty($configNames)) { |
|
| 84 | + foreach ($configNames as $configName) { |
|
| 85 | + if (isset($configValue[$configName])) { |
|
| 86 | + $configValue = $configValue[$configName]; |
|
| 87 | + } else if (!$input->hasParameterOption('--default-value')) { |
|
| 88 | + return 1; |
|
| 89 | + } else { |
|
| 90 | + $configValue = $defaultValue; |
|
| 91 | + break; |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - $this->writeMixedInOutputFormat($input, $output, $configValue); |
|
| 98 | - return 0; |
|
| 99 | - } |
|
| 97 | + $this->writeMixedInOutputFormat($input, $output, $configValue); |
|
| 98 | + return 0; |
|
| 99 | + } |
|
| 100 | 100 | } |