diff --git a/cli/Commands/Config/GetConfigValue.php b/cli/Commands/Config/GetConfigValue.php new file mode 100644 index 0000000000000000000000000000000000000000..f795dd6fe8f6c7842878aacf263012a9720f8ed7 --- /dev/null +++ b/cli/Commands/Config/GetConfigValue.php @@ -0,0 +1,45 @@ +<?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 GetConfigValue extends Command +{ + protected static $defaultName = 'config:get'; + + protected function configure(): void + { + $this->setDescription('Get value of a Stud.IP configuration key.'); + $this->setHelp('This command will return the value of a Stud.IP configuration key.'); + $this->addArgument('config-key', InputArgument::REQUIRED, 'Key of the configuration.'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $configKey = $input->getArgument('config-key'); + + $config = \Config::get(); + $metadata = $config->getMetadata($configKey) ?: [ + 'field' => $configKey, + 'type' => 'string', + 'description' => 'missing in table `config`', + ]; + if (isset($metadata['is_default'])) { + $metadata['is_default'] = $metadata['is_default'] ? 'true' : 'false'; + } + $metadata['value'] = $config->$configKey; + $pairs = array_map(null, array_keys($metadata), array_values($metadata)); + + $table = new Table($output); + $table->setHeaders(['Field', 'Value'])->setRows($pairs); + $table->setStyle('box'); + $table->render(); + + return Command::SUCCESS; + } +} diff --git a/cli/Commands/Config/SetConfigValue.php b/cli/Commands/Config/SetConfigValue.php new file mode 100644 index 0000000000000000000000000000000000000000..75305caa247885dfc8f53314ae730dd4597c20c4 --- /dev/null +++ b/cli/Commands/Config/SetConfigValue.php @@ -0,0 +1,37 @@ +<?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) { + // TODO: + throw new \RuntimeException(); + } + + $result = \Config::get()->store($configKey, $configValue); + + return Command::SUCCESS; + } +} diff --git a/cli/studip b/cli/studip index 36fe5f52dbdaecfa32db5fb66e950e9a7dbce147..58b09df24f83e79aa9f330368ae52f8ae01ae68e 100755 --- a/cli/studip +++ b/cli/studip @@ -18,6 +18,8 @@ $commands = [ Commands\Checks\HelpTours::class, Commands\Checks\HelpTours::class, Commands\CleanupAdmissionRules::class, + Commands\Config\GetConfigValue::class, + Commands\Config\SetConfigValue::class, Commands\Cronjobs\CronjobExecute::class, Commands\Cronjobs\CronjobExecute::class, Commands\Cronjobs\CronjobList::class,