Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
35 / 35 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| set_atomic | |
100.00% |
35 / 35 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| configure | |
100.00% |
25 / 25 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | namespace phpbb\console\command\config; |
| 14 | |
| 15 | use Symfony\Component\Console\Command\Command as symfony_command; |
| 16 | use Symfony\Component\Console\Input\InputArgument; |
| 17 | use Symfony\Component\Console\Input\InputInterface; |
| 18 | use Symfony\Component\Console\Input\InputOption; |
| 19 | use Symfony\Component\Console\Output\OutputInterface; |
| 20 | use Symfony\Component\Console\Style\SymfonyStyle; |
| 21 | |
| 22 | class set_atomic extends command |
| 23 | { |
| 24 | /** |
| 25 | * {@inheritdoc} |
| 26 | */ |
| 27 | protected function configure() |
| 28 | { |
| 29 | $this |
| 30 | ->setName('config:set-atomic') |
| 31 | ->setDescription($this->user->lang('CLI_DESCRIPTION_SET_ATOMIC_CONFIG')) |
| 32 | ->addArgument( |
| 33 | 'key', |
| 34 | InputArgument::REQUIRED, |
| 35 | $this->user->lang('CLI_CONFIG_OPTION_NAME') |
| 36 | ) |
| 37 | ->addArgument( |
| 38 | 'old', |
| 39 | InputArgument::REQUIRED, |
| 40 | $this->user->lang('CLI_CONFIG_CURRENT') |
| 41 | ) |
| 42 | ->addArgument( |
| 43 | 'new', |
| 44 | InputArgument::REQUIRED, |
| 45 | $this->user->lang('CLI_CONFIG_NEW') |
| 46 | ) |
| 47 | ->addOption( |
| 48 | 'dynamic', |
| 49 | 'd', |
| 50 | InputOption::VALUE_NONE, |
| 51 | $this->user->lang('CLI_CONFIG_CANNOT_CACHED') |
| 52 | ) |
| 53 | ; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Executes the command config:set-atomic. |
| 58 | * |
| 59 | * Sets a configuration option's value only if the old_value matches the |
| 60 | * current configuration value or the configuration value does not exist yet. |
| 61 | * |
| 62 | * @param InputInterface $input An InputInterface instance |
| 63 | * @param OutputInterface $output An OutputInterface instance |
| 64 | * |
| 65 | * @return int 0 if the value was changed, 1 otherwise. |
| 66 | * @see \phpbb\config\config::set_atomic() |
| 67 | */ |
| 68 | protected function execute(InputInterface $input, OutputInterface $output): int |
| 69 | { |
| 70 | $io = new SymfonyStyle($input, $output); |
| 71 | |
| 72 | $key = $input->getArgument('key'); |
| 73 | $old_value = $input->getArgument('old'); |
| 74 | $new_value = $input->getArgument('new'); |
| 75 | $use_cache = !$input->getOption('dynamic'); |
| 76 | |
| 77 | if ($this->config->set_atomic($key, $old_value, $new_value, $use_cache)) |
| 78 | { |
| 79 | $io->success($this->user->lang('CLI_CONFIG_SET_SUCCESS', $key)); |
| 80 | return symfony_command::SUCCESS; |
| 81 | } |
| 82 | else |
| 83 | { |
| 84 | $io->error($this->user->lang('CLI_CONFIG_SET_FAILURE', $key)); |
| 85 | return symfony_command::FAILURE; |
| 86 | } |
| 87 | } |
| 88 | } |