aboutsummaryrefslogtreecommitdiffstats
path: root/apps/theming/lib/Command
diff options
context:
space:
mode:
Diffstat (limited to 'apps/theming/lib/Command')
-rw-r--r--apps/theming/lib/Command/UpdateConfig.php71
1 files changed, 31 insertions, 40 deletions
diff --git a/apps/theming/lib/Command/UpdateConfig.php b/apps/theming/lib/Command/UpdateConfig.php
index 001bc2d2d76..6236f866445 100644
--- a/apps/theming/lib/Command/UpdateConfig.php
+++ b/apps/theming/lib/Command/UpdateConfig.php
@@ -1,26 +1,9 @@
<?php
+
/**
- * @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
- *
- * @author Julius Härtl <jus@bitgrid.net>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-
namespace OCA\Theming\Command;
use OCA\Theming\ImageManager;
@@ -34,23 +17,15 @@ use Symfony\Component\Console\Output\OutputInterface;
class UpdateConfig extends Command {
public const SUPPORTED_KEYS = [
- 'name', 'url', 'imprintUrl', 'privacyUrl', 'slogan', 'color'
- ];
-
- public const SUPPORTED_IMAGE_KEYS = [
- 'background', 'logo', 'favicon', 'logoheader'
+ 'name', 'url', 'imprintUrl', 'privacyUrl', 'slogan', 'color', 'primary_color', 'background_color', 'disable-user-theming'
];
- private $themingDefaults;
- private $imageManager;
- private $config;
-
- public function __construct(ThemingDefaults $themingDefaults, ImageManager $imageManager, IConfig $config) {
+ public function __construct(
+ private ThemingDefaults $themingDefaults,
+ private ImageManager $imageManager,
+ private IConfig $config,
+ ) {
parent::__construct();
-
- $this->themingDefaults = $themingDefaults;
- $this->imageManager = $imageManager;
- $this->config = $config;
}
protected function configure() {
@@ -60,8 +35,8 @@ class UpdateConfig extends Command {
->addArgument(
'key',
InputArgument::OPTIONAL,
- 'Key to update the theming app configuration (leave empty to get a list of all configured values)' . PHP_EOL .
- 'One of: ' . implode(', ', self::SUPPORTED_KEYS)
+ 'Key to update the theming app configuration (leave empty to get a list of all configured values)' . PHP_EOL
+ . 'One of: ' . implode(', ', self::SUPPORTED_KEYS)
)
->addArgument(
'value',
@@ -80,6 +55,7 @@ class UpdateConfig extends Command {
protected function execute(InputInterface $input, OutputInterface $output): int {
$key = $input->getArgument('key');
$value = $input->getArgument('value');
+ assert(is_string($value) || $value === null, 'At most one value should be provided.');
if ($key === null) {
$output->writeln('Current theming config:');
@@ -87,14 +63,14 @@ class UpdateConfig extends Command {
$value = $this->config->getAppValue('theming', $key, '');
$output->writeln('- ' . $key . ': ' . $value . '');
}
- foreach (self::SUPPORTED_IMAGE_KEYS as $key) {
+ foreach (ImageManager::SUPPORTED_IMAGE_KEYS as $key) {
$value = $this->config->getAppValue('theming', $key . 'Mime', '');
$output->writeln('- ' . $key . ': ' . $value . '');
}
return 0;
}
- if (!in_array($key, self::SUPPORTED_KEYS, true) && !in_array($key, self::SUPPORTED_IMAGE_KEYS, true)) {
+ if (!in_array($key, self::SUPPORTED_KEYS, true) && !in_array($key, ImageManager::SUPPORTED_IMAGE_KEYS, true)) {
$output->writeln('<error>Invalid config key provided</error>');
return 1;
}
@@ -115,8 +91,13 @@ class UpdateConfig extends Command {
return 0;
}
- if (in_array($key, self::SUPPORTED_IMAGE_KEYS, true)) {
- if (strpos($value, '/') !== 0) {
+ if ($key === 'background' && $value === 'backgroundColor') {
+ $this->themingDefaults->undo($key);
+ $key = $key . 'Mime';
+ }
+
+ if (in_array($key, ImageManager::SUPPORTED_IMAGE_KEYS, true)) {
+ if (!str_starts_with($value, '/')) {
$output->writeln('<error>The image file needs to be provided as an absolute path: ' . $value . '.</error>');
return 1;
}
@@ -128,6 +109,16 @@ class UpdateConfig extends Command {
$key = $key . 'Mime';
}
+ if ($key === 'color') {
+ $output->writeln('<comment>Using "color" is deprecated, use "primary_color" instead</comment>');
+ $key = 'primary_color';
+ }
+
+ if ($key === 'primary_color' && !preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) {
+ $output->writeln('<error>The given color is invalid: ' . $value . '</error>');
+ return 1;
+ }
+
$this->themingDefaults->set($key, $value);
$output->writeln('<info>Updated ' . $key . ' to ' . $value . '</info>');