From ca614c2aac92433910935709ec608b112bf39297 Mon Sep 17 00:00:00 2001 From: Johannes Nielsen <johannes.nielsen@artundweise.de> Date: Mon, 12 Jun 2023 10:25:42 +0200 Subject: [PATCH] [BUGFIX] Respect default values in setup command So far the setup command did not consider default values in non-interactive mode. This led to unexpected errors when not passing in parameters, which should have default values, as either CLI parameters or ENV variables. Resolves: #100945 Releases: main, 12.4 Change-Id: If811c5c1ef9b7d8a5c776af407fac7d2ced4e654 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/79831 Tested-by: core-ci <typo3@b13.com> Tested-by: Benni Mack <benni@typo3.org> Reviewed-by: Benni Mack <benni@typo3.org> --- .../install/Classes/Command/SetupCommand.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/typo3/sysext/install/Classes/Command/SetupCommand.php b/typo3/sysext/install/Classes/Command/SetupCommand.php index 4cf7ae647adc..12d38cc3add5 100644 --- a/typo3/sysext/install/Classes/Command/SetupCommand.php +++ b/typo3/sysext/install/Classes/Command/SetupCommand.php @@ -80,7 +80,7 @@ class SetupCommand extends Command ->addOption( 'port', null, - InputOption::VALUE_REQUIRED, + InputOption::VALUE_OPTIONAL, 'Set the database port to use', '3306' ) @@ -108,7 +108,7 @@ class SetupCommand extends Command ->addOption( 'admin-username', null, - InputOption::VALUE_REQUIRED, + InputOption::VALUE_OPTIONAL, 'Set a username', 'admin' ) @@ -461,6 +461,7 @@ EOT // All passed in values should go through the set validator, // therefore, we can't break early $validator = $question->getValidator(); + $envValue = $envValue ?: $default; $value = $validator ? $validator($envValue) : $envValue; } @@ -491,6 +492,11 @@ EOT return $questionHelper->ask($input, $output, $questionUsername); } + // Use default value for 'admin-username' if in non-interactive mode + if ($usernameFromCli === false && !$input->isInteractive()) { + $usernameFromCli = $this->getDefinition()->getOption('admin-username')->getDefault(); + } + return $usernameValidator($usernameFromCli); } @@ -528,7 +534,7 @@ EOT return $passwordValidator($passwordFromCli); } - protected function getAdminEmailAddress(QuestionHelper $questionHelper, InputInterface $input, OutputInterface $output): string|false + protected function getAdminEmailAddress(QuestionHelper $questionHelper, InputInterface $input, OutputInterface $output): string { $emailValidator = static function ($email) { if (!empty($email) && !GeneralUtility::validEmail($email)) { @@ -549,7 +555,7 @@ EOT return $questionHelper->ask($input, $output, $questionEmail); } - return $emailValidator($emailFromCli); + return (string)$emailValidator($emailFromCli); } protected function getProjectName(QuestionHelper $questionHelper, InputInterface $input, OutputInterface $output): string -- GitLab