diff --git a/src/CliCommand/UserConfigSet.php b/src/CliCommand/UserConfigSet.php new file mode 100644 index 00000000..f40beec9 --- /dev/null +++ b/src/CliCommand/UserConfigSet.php @@ -0,0 +1,97 @@ +mvcFactory->makeTempModel('Users'); + $id = intval($input->getArgument('id')); + + try + { + $model->findOrFail($id); + } + catch (\Exception $e) + { + $this->ioStyle->error( + [ + sprintf('Could not find user %d', $id), + $e->getMessage(), + ] + ); + + return Command::FAILURE; + } + + $config = new Registry($model->parameters); + + $key = $input->getArgument('key') ?? ''; + $value = $input->getArgument('value') ?? ''; + $config->set($key, $value); + + try + { + $model->save( + [ + 'parameters' => $config->toString(), + ] + ); + } + catch (\Exception $e) + { + $this->ioStyle->error( + [ + 'Could not save user configuration variable', + $e->getMessage(), + ] + ); + + return Command::FAILURE; + } + + $this->ioStyle->success( + sprintf('Set config key ā€˜%sā€™ to ā€˜%sā€™ for user %d.', $key, $value, $id) + ); + + return Command::SUCCESS; + } + + protected function configure(): void + { + $this + ->addArgument('id', InputArgument::REQUIRED, 'The numeric user ID to list config values for') + ->addArgument('key', InputArgument::REQUIRED, 'The configuration key to get the value for') + ->addArgument('value', InputArgument::REQUIRED, 'The configuration value to set'); + } +} \ No newline at end of file