parent
af5acc35cd
commit
e64be71e52
@ -0,0 +1,71 @@ |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
/** |
||||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
||||
* SPDX-License-Identifier: AGPL-3.0-or-later |
||||
*/ |
||||
namespace OC\Core\Command\Config; |
||||
|
||||
use NCU\Config\Lexicon\Preset as ConfigLexiconPreset; |
||||
use OC\Config\ConfigManager; |
||||
use OC\Core\Command\Base; |
||||
use OCP\IConfig; |
||||
use Symfony\Component\Console\Input\InputArgument; |
||||
use Symfony\Component\Console\Input\InputInterface; |
||||
use Symfony\Component\Console\Input\InputOption; |
||||
use Symfony\Component\Console\Output\OutputInterface; |
||||
|
||||
class Preset extends Base { |
||||
public function __construct( |
||||
private readonly IConfig $config, |
||||
private readonly ConfigManager $configManager, |
||||
) { |
||||
parent::__construct(); |
||||
} |
||||
|
||||
protected function configure() { |
||||
parent::configure(); |
||||
$this->setName('config:preset') |
||||
->setDescription('Select a config preset') |
||||
->addArgument('preset', InputArgument::OPTIONAL, 'Preset to use for all unset config values', '') |
||||
->addOption('list', '', InputOption::VALUE_NONE, 'display available preset'); |
||||
} |
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int { |
||||
if ($input->getOption('list')) { |
||||
$this->getEnum('', $list); |
||||
$this->writeArrayInOutputFormat($input, $output, $list); |
||||
return self::SUCCESS; |
||||
} |
||||
|
||||
$presetArg = $input->getArgument('preset'); |
||||
if ($presetArg !== '') { |
||||
$preset = $this->getEnum($presetArg, $list); |
||||
if ($preset === null) { |
||||
$output->writeln('<error>Invalid preset: ' . $presetArg . '</error>'); |
||||
$output->writeln('Available presets: ' . implode(', ', $list)); |
||||
return self::INVALID; |
||||
} |
||||
|
||||
$this->configManager->setLexiconPreset($preset); |
||||
} |
||||
|
||||
$current = ConfigLexiconPreset::tryFrom($this->config->getSystemValueInt(ConfigManager::PRESET_CONFIGKEY, 0)) ?? ConfigLexiconPreset::NONE; |
||||
$this->writeArrayInOutputFormat($input, $output, [$current->name], 'current preset: '); |
||||
return self::SUCCESS; |
||||
} |
||||
|
||||
private function getEnum(string $name, ?array &$list = null): ?ConfigLexiconPreset { |
||||
$list = []; |
||||
foreach (ConfigLexiconPreset::cases() as $case) { |
||||
$list[] = $case->name; |
||||
if (strtolower($case->name) === strtolower($name)) { |
||||
return $case; |
||||
} |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
} |
||||
@ -0,0 +1,46 @@ |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
/** |
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
||||
* SPDX-License-Identifier: AGPL-3.0-only |
||||
*/ |
||||
|
||||
namespace NCU\Config\Lexicon; |
||||
|
||||
/** |
||||
* list of preset to handle the default behavior of the instance |
||||
* |
||||
* @see ConfigLexiconEntry::preset |
||||
* |
||||
* - **Preset::LARGE** - Large size organisation (> 50k accounts) |
||||
* - **Preset::MEDIUM** - Medium size organisation (> 100 accounts) |
||||
* - **Preset::SMALL** - Small size organisation (< 100 accounts) |
||||
* - **Preset::SHARED** - Shared hosting |
||||
* - **Preset::EDUCATION** - School/University |
||||
* - **Preset::CLUB** - Club/Association |
||||
* - **Preset::FAMILY** - Family |
||||
* - **Preset::PRIVATE** - Private |
||||
* |
||||
* @experimental 32.0.0 |
||||
*/ |
||||
enum Preset: int { |
||||
/** @experimental 32.0.0 */ |
||||
case LARGE = 8; |
||||
/** @experimental 32.0.0 */ |
||||
case MEDIUM = 7; |
||||
/** @experimental 32.0.0 */ |
||||
case SMALL = 6; |
||||
/** @experimental 32.0.0 */ |
||||
case SHARED = 5; |
||||
/** @experimental 32.0.0 */ |
||||
case EDUCATION = 4; |
||||
/** @experimental 32.0.0 */ |
||||
case CLUB = 3; |
||||
/** @experimental 32.0.0 */ |
||||
case FAMILY = 2; |
||||
/** @experimental 32.0.0 */ |
||||
case PRIVATE = 1; |
||||
/** @experimental 32.0.0 */ |
||||
case NONE = 0; |
||||
} |
||||
Loading…
Reference in new issue