diff options
| author | Marcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de> | 2023-05-16 09:17:37 +0000 |
|---|---|---|
| committer | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2023-05-16 09:17:37 +0000 |
| commit | 1de91f34232717544892bfddd3314900edf91f3b (patch) | |
| tree | 4ec7e15e07499ffe631135c2ae36a7da4da54588 /cli/Commands/Config/SetConfigValue.php | |
| parent | 132e3454d06db698ca5c184050b4a4aadef9d574 (diff) | |
Add CLI scripts to get and set global configuration.
Closes #2588
Merge request studip/studip!1746
Diffstat (limited to 'cli/Commands/Config/SetConfigValue.php')
| -rw-r--r-- | cli/Commands/Config/SetConfigValue.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/cli/Commands/Config/SetConfigValue.php b/cli/Commands/Config/SetConfigValue.php new file mode 100644 index 0000000..9444dc9 --- /dev/null +++ b/cli/Commands/Config/SetConfigValue.php @@ -0,0 +1,36 @@ +<?php + +namespace Studip\Cli\Commands\Config; + +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Helper\Table; + +class SetConfigValue extends Command +{ + protected static $defaultName = 'config:set'; + + protected function configure(): void + { + $this->setDescription('Set value of a Stud.IP configuration key.'); + $this->setHelp('This command will set the value of a Stud.IP configuration key.'); + $this->addArgument('config-key', InputArgument::REQUIRED, 'Key of the configuration.'); + $this->addArgument('config-value', InputArgument::REQUIRED, 'Value of the configuration.'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $configKey = $input->getArgument('config-key'); + $configValue = $input->getArgument('config-value'); + $metadata = \Config::get()->getMetadata($configKey); + if (!$metadata) { + throw new \RuntimeException("Unknown config key '{$configKey}"); + } + + \Config::get()->store($configKey, $configValue); + + return Command::SUCCESS; + } +} |
