Skip to content
Snippets Groups Projects
Commit 5b09f5ab authored by Marcus Eibrink-Lunzenauer's avatar Marcus Eibrink-Lunzenauer
Browse files

Add CLI scripts to get and set global configuration.

Fixes #2588.
parent 08b4ccb9
No related branches found
No related tags found
No related merge requests found
Pipeline #12032 passed
<?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;
}
}
<?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;
}
}
...@@ -18,6 +18,8 @@ $commands = [ ...@@ -18,6 +18,8 @@ $commands = [
Commands\Checks\HelpTours::class, Commands\Checks\HelpTours::class,
Commands\Checks\HelpTours::class, Commands\Checks\HelpTours::class,
Commands\CleanupAdmissionRules::class, Commands\CleanupAdmissionRules::class,
Commands\Config\GetConfigValue::class,
Commands\Config\SetConfigValue::class,
Commands\Cronjobs\CronjobExecute::class, Commands\Cronjobs\CronjobExecute::class,
Commands\Cronjobs\CronjobExecute::class, Commands\Cronjobs\CronjobExecute::class,
Commands\Cronjobs\CronjobList::class, Commands\Cronjobs\CronjobList::class,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment