@@ -32,111 +32,111 @@ |
||
| 32 | 32 | use Symfony\Component\Console\Output\OutputInterface; |
| 33 | 33 | |
| 34 | 34 | class UpdateConfig extends Command { |
| 35 | - public const SUPPORTED_KEYS = [ |
|
| 36 | - 'name', 'url', 'imprintUrl', 'privacyUrl', 'slogan', 'color', 'disable-user-theming' |
|
| 37 | - ]; |
|
| 38 | - |
|
| 39 | - private $themingDefaults; |
|
| 40 | - private $imageManager; |
|
| 41 | - private $config; |
|
| 42 | - |
|
| 43 | - public function __construct(ThemingDefaults $themingDefaults, ImageManager $imageManager, IConfig $config) { |
|
| 44 | - parent::__construct(); |
|
| 45 | - |
|
| 46 | - $this->themingDefaults = $themingDefaults; |
|
| 47 | - $this->imageManager = $imageManager; |
|
| 48 | - $this->config = $config; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - protected function configure() { |
|
| 52 | - $this |
|
| 53 | - ->setName('theming:config') |
|
| 54 | - ->setDescription('Set theming app config values') |
|
| 55 | - ->addArgument( |
|
| 56 | - 'key', |
|
| 57 | - InputArgument::OPTIONAL, |
|
| 58 | - 'Key to update the theming app configuration (leave empty to get a list of all configured values)' . PHP_EOL . |
|
| 59 | - 'One of: ' . implode(', ', self::SUPPORTED_KEYS) |
|
| 60 | - ) |
|
| 61 | - ->addArgument( |
|
| 62 | - 'value', |
|
| 63 | - InputArgument::OPTIONAL, |
|
| 64 | - 'Value to set (leave empty to obtain the current value)' |
|
| 65 | - ) |
|
| 66 | - ->addOption( |
|
| 67 | - 'reset', |
|
| 68 | - 'r', |
|
| 69 | - InputOption::VALUE_NONE, |
|
| 70 | - 'Reset the given config key to default' |
|
| 71 | - ); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 76 | - $key = $input->getArgument('key'); |
|
| 77 | - $value = $input->getArgument('value'); |
|
| 78 | - assert(is_string($value) || $value === null, 'At most one value should be provided.'); |
|
| 79 | - |
|
| 80 | - if ($key === null) { |
|
| 81 | - $output->writeln('Current theming config:'); |
|
| 82 | - foreach (self::SUPPORTED_KEYS as $key) { |
|
| 83 | - $value = $this->config->getAppValue('theming', $key, ''); |
|
| 84 | - $output->writeln('- ' . $key . ': ' . $value . ''); |
|
| 85 | - } |
|
| 86 | - foreach (ImageManager::SUPPORTED_IMAGE_KEYS as $key) { |
|
| 87 | - $value = $this->config->getAppValue('theming', $key . 'Mime', ''); |
|
| 88 | - $output->writeln('- ' . $key . ': ' . $value . ''); |
|
| 89 | - } |
|
| 90 | - return 0; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - if (!in_array($key, self::SUPPORTED_KEYS, true) && !in_array($key, ImageManager::SUPPORTED_IMAGE_KEYS, true)) { |
|
| 94 | - $output->writeln('<error>Invalid config key provided</error>'); |
|
| 95 | - return 1; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - if ($input->getOption('reset')) { |
|
| 99 | - $defaultValue = $this->themingDefaults->undo($key); |
|
| 100 | - $output->writeln('<info>Reset ' . $key . ' to ' . $defaultValue . '</info>'); |
|
| 101 | - return 0; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - if ($value === null) { |
|
| 105 | - $value = $this->config->getAppValue('theming', $key, ''); |
|
| 106 | - if ($value !== '') { |
|
| 107 | - $output->writeln('<info>' . $key . ' is currently set to ' . $value . '</info>'); |
|
| 108 | - } else { |
|
| 109 | - $output->writeln('<info>' . $key . ' is currently not set</info>'); |
|
| 110 | - } |
|
| 111 | - return 0; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - if ($key === 'background' && $value === 'backgroundColor') { |
|
| 115 | - $this->themingDefaults->undo($key); |
|
| 116 | - $key = $key . 'Mime'; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - if (in_array($key, ImageManager::SUPPORTED_IMAGE_KEYS, true)) { |
|
| 120 | - if (!str_starts_with($value, '/')) { |
|
| 121 | - $output->writeln('<error>The image file needs to be provided as an absolute path: ' . $value . '.</error>'); |
|
| 122 | - return 1; |
|
| 123 | - } |
|
| 124 | - if (!file_exists($value)) { |
|
| 125 | - $output->writeln('<error>File could not be found: ' . $value . '.</error>'); |
|
| 126 | - return 1; |
|
| 127 | - } |
|
| 128 | - $value = $this->imageManager->updateImage($key, $value); |
|
| 129 | - $key = $key . 'Mime'; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - if ($key === 'color' && !preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) { |
|
| 133 | - $output->writeln('<error>The given color is invalid: ' . $value . '</error>'); |
|
| 134 | - return 1; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $this->themingDefaults->set($key, $value); |
|
| 138 | - $output->writeln('<info>Updated ' . $key . ' to ' . $value . '</info>'); |
|
| 139 | - |
|
| 140 | - return 0; |
|
| 141 | - } |
|
| 35 | + public const SUPPORTED_KEYS = [ |
|
| 36 | + 'name', 'url', 'imprintUrl', 'privacyUrl', 'slogan', 'color', 'disable-user-theming' |
|
| 37 | + ]; |
|
| 38 | + |
|
| 39 | + private $themingDefaults; |
|
| 40 | + private $imageManager; |
|
| 41 | + private $config; |
|
| 42 | + |
|
| 43 | + public function __construct(ThemingDefaults $themingDefaults, ImageManager $imageManager, IConfig $config) { |
|
| 44 | + parent::__construct(); |
|
| 45 | + |
|
| 46 | + $this->themingDefaults = $themingDefaults; |
|
| 47 | + $this->imageManager = $imageManager; |
|
| 48 | + $this->config = $config; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + protected function configure() { |
|
| 52 | + $this |
|
| 53 | + ->setName('theming:config') |
|
| 54 | + ->setDescription('Set theming app config values') |
|
| 55 | + ->addArgument( |
|
| 56 | + 'key', |
|
| 57 | + InputArgument::OPTIONAL, |
|
| 58 | + 'Key to update the theming app configuration (leave empty to get a list of all configured values)' . PHP_EOL . |
|
| 59 | + 'One of: ' . implode(', ', self::SUPPORTED_KEYS) |
|
| 60 | + ) |
|
| 61 | + ->addArgument( |
|
| 62 | + 'value', |
|
| 63 | + InputArgument::OPTIONAL, |
|
| 64 | + 'Value to set (leave empty to obtain the current value)' |
|
| 65 | + ) |
|
| 66 | + ->addOption( |
|
| 67 | + 'reset', |
|
| 68 | + 'r', |
|
| 69 | + InputOption::VALUE_NONE, |
|
| 70 | + 'Reset the given config key to default' |
|
| 71 | + ); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 76 | + $key = $input->getArgument('key'); |
|
| 77 | + $value = $input->getArgument('value'); |
|
| 78 | + assert(is_string($value) || $value === null, 'At most one value should be provided.'); |
|
| 79 | + |
|
| 80 | + if ($key === null) { |
|
| 81 | + $output->writeln('Current theming config:'); |
|
| 82 | + foreach (self::SUPPORTED_KEYS as $key) { |
|
| 83 | + $value = $this->config->getAppValue('theming', $key, ''); |
|
| 84 | + $output->writeln('- ' . $key . ': ' . $value . ''); |
|
| 85 | + } |
|
| 86 | + foreach (ImageManager::SUPPORTED_IMAGE_KEYS as $key) { |
|
| 87 | + $value = $this->config->getAppValue('theming', $key . 'Mime', ''); |
|
| 88 | + $output->writeln('- ' . $key . ': ' . $value . ''); |
|
| 89 | + } |
|
| 90 | + return 0; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + if (!in_array($key, self::SUPPORTED_KEYS, true) && !in_array($key, ImageManager::SUPPORTED_IMAGE_KEYS, true)) { |
|
| 94 | + $output->writeln('<error>Invalid config key provided</error>'); |
|
| 95 | + return 1; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + if ($input->getOption('reset')) { |
|
| 99 | + $defaultValue = $this->themingDefaults->undo($key); |
|
| 100 | + $output->writeln('<info>Reset ' . $key . ' to ' . $defaultValue . '</info>'); |
|
| 101 | + return 0; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + if ($value === null) { |
|
| 105 | + $value = $this->config->getAppValue('theming', $key, ''); |
|
| 106 | + if ($value !== '') { |
|
| 107 | + $output->writeln('<info>' . $key . ' is currently set to ' . $value . '</info>'); |
|
| 108 | + } else { |
|
| 109 | + $output->writeln('<info>' . $key . ' is currently not set</info>'); |
|
| 110 | + } |
|
| 111 | + return 0; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + if ($key === 'background' && $value === 'backgroundColor') { |
|
| 115 | + $this->themingDefaults->undo($key); |
|
| 116 | + $key = $key . 'Mime'; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + if (in_array($key, ImageManager::SUPPORTED_IMAGE_KEYS, true)) { |
|
| 120 | + if (!str_starts_with($value, '/')) { |
|
| 121 | + $output->writeln('<error>The image file needs to be provided as an absolute path: ' . $value . '.</error>'); |
|
| 122 | + return 1; |
|
| 123 | + } |
|
| 124 | + if (!file_exists($value)) { |
|
| 125 | + $output->writeln('<error>File could not be found: ' . $value . '.</error>'); |
|
| 126 | + return 1; |
|
| 127 | + } |
|
| 128 | + $value = $this->imageManager->updateImage($key, $value); |
|
| 129 | + $key = $key . 'Mime'; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + if ($key === 'color' && !preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) { |
|
| 133 | + $output->writeln('<error>The given color is invalid: ' . $value . '</error>'); |
|
| 134 | + return 1; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $this->themingDefaults->set($key, $value); |
|
| 138 | + $output->writeln('<info>Updated ' . $key . ' to ' . $value . '</info>'); |
|
| 139 | + |
|
| 140 | + return 0; |
|
| 141 | + } |
|
| 142 | 142 | } |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | ->addArgument( |
| 56 | 56 | 'key', |
| 57 | 57 | InputArgument::OPTIONAL, |
| 58 | - 'Key to update the theming app configuration (leave empty to get a list of all configured values)' . PHP_EOL . |
|
| 59 | - 'One of: ' . implode(', ', self::SUPPORTED_KEYS) |
|
| 58 | + 'Key to update the theming app configuration (leave empty to get a list of all configured values)'.PHP_EOL. |
|
| 59 | + 'One of: '.implode(', ', self::SUPPORTED_KEYS) |
|
| 60 | 60 | ) |
| 61 | 61 | ->addArgument( |
| 62 | 62 | 'value', |
@@ -81,11 +81,11 @@ discard block |
||
| 81 | 81 | $output->writeln('Current theming config:'); |
| 82 | 82 | foreach (self::SUPPORTED_KEYS as $key) { |
| 83 | 83 | $value = $this->config->getAppValue('theming', $key, ''); |
| 84 | - $output->writeln('- ' . $key . ': ' . $value . ''); |
|
| 84 | + $output->writeln('- '.$key.': '.$value.''); |
|
| 85 | 85 | } |
| 86 | 86 | foreach (ImageManager::SUPPORTED_IMAGE_KEYS as $key) { |
| 87 | - $value = $this->config->getAppValue('theming', $key . 'Mime', ''); |
|
| 88 | - $output->writeln('- ' . $key . ': ' . $value . ''); |
|
| 87 | + $value = $this->config->getAppValue('theming', $key.'Mime', ''); |
|
| 88 | + $output->writeln('- '.$key.': '.$value.''); |
|
| 89 | 89 | } |
| 90 | 90 | return 0; |
| 91 | 91 | } |
@@ -97,45 +97,45 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | if ($input->getOption('reset')) { |
| 99 | 99 | $defaultValue = $this->themingDefaults->undo($key); |
| 100 | - $output->writeln('<info>Reset ' . $key . ' to ' . $defaultValue . '</info>'); |
|
| 100 | + $output->writeln('<info>Reset '.$key.' to '.$defaultValue.'</info>'); |
|
| 101 | 101 | return 0; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | if ($value === null) { |
| 105 | 105 | $value = $this->config->getAppValue('theming', $key, ''); |
| 106 | 106 | if ($value !== '') { |
| 107 | - $output->writeln('<info>' . $key . ' is currently set to ' . $value . '</info>'); |
|
| 107 | + $output->writeln('<info>'.$key.' is currently set to '.$value.'</info>'); |
|
| 108 | 108 | } else { |
| 109 | - $output->writeln('<info>' . $key . ' is currently not set</info>'); |
|
| 109 | + $output->writeln('<info>'.$key.' is currently not set</info>'); |
|
| 110 | 110 | } |
| 111 | 111 | return 0; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | if ($key === 'background' && $value === 'backgroundColor') { |
| 115 | 115 | $this->themingDefaults->undo($key); |
| 116 | - $key = $key . 'Mime'; |
|
| 116 | + $key = $key.'Mime'; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | if (in_array($key, ImageManager::SUPPORTED_IMAGE_KEYS, true)) { |
| 120 | 120 | if (!str_starts_with($value, '/')) { |
| 121 | - $output->writeln('<error>The image file needs to be provided as an absolute path: ' . $value . '.</error>'); |
|
| 121 | + $output->writeln('<error>The image file needs to be provided as an absolute path: '.$value.'.</error>'); |
|
| 122 | 122 | return 1; |
| 123 | 123 | } |
| 124 | 124 | if (!file_exists($value)) { |
| 125 | - $output->writeln('<error>File could not be found: ' . $value . '.</error>'); |
|
| 125 | + $output->writeln('<error>File could not be found: '.$value.'.</error>'); |
|
| 126 | 126 | return 1; |
| 127 | 127 | } |
| 128 | 128 | $value = $this->imageManager->updateImage($key, $value); |
| 129 | - $key = $key . 'Mime'; |
|
| 129 | + $key = $key.'Mime'; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | if ($key === 'color' && !preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) { |
| 133 | - $output->writeln('<error>The given color is invalid: ' . $value . '</error>'); |
|
| 133 | + $output->writeln('<error>The given color is invalid: '.$value.'</error>'); |
|
| 134 | 134 | return 1; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | $this->themingDefaults->set($key, $value); |
| 138 | - $output->writeln('<info>Updated ' . $key . ' to ' . $value . '</info>'); |
|
| 138 | + $output->writeln('<info>Updated '.$key.' to '.$value.'</info>'); |
|
| 139 | 139 | |
| 140 | 140 | return 0; |
| 141 | 141 | } |