Skip to content

Commit e235c71

Browse files
committed
Implement manual prefix setting for configuration
Add option to manually set configuration prefix with validation. Signed-off-by: Jean-Yves <[email protected]>
1 parent 3a687ea commit e235c71

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

apps/user_ldap/lib/Command/CreateEmptyConfig.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,34 @@ protected function configure(): void {
3131
InputOption::VALUE_NONE,
3232
'outputs only the prefix'
3333
)
34+
->addOption(
35+
'set-prefix',
36+
's',
37+
InputOption::VALUE_OPTIONAL,
38+
'manually set the prefix (must be unique)',
39+
)
3440
;
3541
}
3642

3743
protected function execute(InputInterface $input, OutputInterface $output): int {
38-
$configPrefix = $this->helper->getNextServerConfigurationPrefix();
44+
$configPrefix = $input->getOption('set-prefix');
45+
if (is_string($configPrefix)) {
46+
if ($configPrefix === '') {
47+
$output->writeln('The prefix cannot be empty');
48+
return self::FAILURE;
49+
}
50+
if (preg_match('/^[a-zA-Z0-9-_]+$/', $configPrefix) !== 1) {
51+
$output->writeln('The prefix may only contain alphanumeric characters, dashes and underscores');
52+
return self::FAILURE;
53+
}
54+
$availableConfigs = $this->helper->getServerConfigurationPrefixes();
55+
if (in_array($configPrefix, $availableConfigs)) {
56+
$output->writeln('The prefix is already in use');
57+
return self::FAILURE;
58+
}
59+
} else {
60+
$configPrefix = $this->helper->getNextServerConfigurationPrefix();
61+
}
3962
$configHolder = new Configuration($configPrefix);
4063
$configHolder->ldapConfigurationActive = false;
4164
$configHolder->saveConfiguration();

0 commit comments

Comments
 (0)