6 declare(strict_types=1);
13 use Magento\Framework\Setup\Declaration\Schema\Request;
18 use Symfony\Component\Console\Input\InputInterface;
19 use Symfony\Component\Console\Output\OutputInterface;
20 use Symfony\Component\Console\Input\InputOption;
21 use Symfony\Component\Console\Input\ArrayInput;
22 use Symfony\Component\Console\Question\Question;
23 use Symfony\Component\Console\Question\ChoiceQuestion;
24 use Symfony\Component\Console\Helper\QuestionHelper;
96 private $installerFactory;
127 $this->installerFactory = $installerFactory;
131 parent::__construct();
139 $inputOptions = $this->configModel->getAvailableOptions();
140 $inputOptions = array_merge($inputOptions, $this->userConfig->getOptionsList());
141 $inputOptions = array_merge($inputOptions, $this->adminUser->getOptionsList(InputOption::VALUE_OPTIONAL));
142 $inputOptions = array_merge($inputOptions, [
144 self::INPUT_KEY_CLEANUP_DB,
146 InputOption::VALUE_NONE,
147 'Cleanup the database before installation' 150 self::INPUT_KEY_SALES_ORDER_INCREMENT_PREFIX,
152 InputOption::VALUE_REQUIRED,
153 'Sales order number prefix' 156 self::INPUT_KEY_USE_SAMPLE_DATA,
158 InputOption::VALUE_NONE,
162 self::INPUT_KEY_ENABLE_MODULES,
164 InputOption::VALUE_OPTIONAL,
165 'List of comma-separated module names. That must be included during installation. ' 166 .
'Available magic param "all".' 169 self::INPUT_KEY_DISABLE_MODULES,
171 InputOption::VALUE_OPTIONAL,
172 'List of comma-separated module names. That must be avoided during installation. ' 173 .
'Available magic param "all".' 176 self::CONVERT_OLD_SCRIPTS_KEY,
178 InputOption::VALUE_OPTIONAL,
179 'Allows to convert old scripts (InstallSchema, UpgradeSchema) to db_schema.xml format',
183 self::INPUT_KEY_INTERACTIVE_SETUP,
184 self::INPUT_KEY_INTERACTIVE_SETUP_SHORTCUT,
185 InputOption::VALUE_NONE,
186 'Interactive Magento instalation' 191 InputOption::VALUE_OPTIONAL,
192 'Safe installation of Magento with dumps on destructive operations, like column removal' 197 InputOption::VALUE_OPTIONAL,
198 'Restore removed data from dumps' 203 InputOption::VALUE_OPTIONAL,
204 'Magento Installation will be run in dry-run mode',
208 $this->setName(
'setup:install')
209 ->setDescription(
'Installs the Magento application')
210 ->setDefinition($inputOptions);
220 $installer = $this->installerFactory->create($consoleLogger);
224 $arrayInput =
new ArrayInput([]);
225 $arrayInput->setInteractive($input->isInteractive());
226 $importConfigCommand->run($arrayInput,
$output);
234 $inputOptions = $input->getOptions();
236 if ($inputOptions[
'interactive']) {
237 $configOptionsToValidate = $this->interactiveQuestions($input,
$output);
239 $configOptionsToValidate = [];
240 foreach ($this->configModel->getAvailableOptions() as
$option) {
241 if (array_key_exists(
$option->getName(), $inputOptions)) {
242 $configOptionsToValidate[
$option->getName()] = $inputOptions[
$option->getName()];
247 if ($inputOptions[
'interactive']) {
249 foreach ($configOptionsToValidate as $key =>
$value) {
250 $command .=
" --{$key}={$value}";
252 $output->writeln(
"<comment>Try re-running command: php bin/magento setup:install{$command}</comment>");
255 $errors = $this->configModel->validate($configOptionsToValidate);
258 $errors = array_merge(
$errors, $this->userConfig->validate($input));
262 $output->writeln(
"<error>$error</error>");
264 throw new \InvalidArgumentException(
'Parameter validation failed');
277 public function validate(InputInterface $input) : array
280 $value = $input->getOption(self::INPUT_KEY_SALES_ORDER_INCREMENT_PREFIX);
281 if (preg_match(self::SALES_ORDER_INCREMENT_PREFIX_RULE, (
string)
$value) != 1) {
282 $errors[] =
'Validation failed, ' . self::INPUT_KEY_SALES_ORDER_INCREMENT_PREFIX
283 .
' must be 20 characters or less';
297 private function interactiveQuestions(InputInterface $input, OutputInterface
$output) : array
299 $helper = $this->getHelper(
'question');
300 $configOptionsToValidate = [];
302 foreach ($this->configModel->getAvailableOptions() as
$option) {
303 $configOptionsToValidate[
$option->getName()] = $this->askQuestion(
314 foreach ($this->userConfig->getOptionsList() as
$option) {
315 $configOptionsToValidate[
$option->getName()] = $this->askQuestion(
325 foreach ($this->adminUser->getOptionsList(InputOption::VALUE_OPTIONAL) as
$option) {
326 $configOptionsToValidate[
$option->getName()] = $this->askQuestion(
336 $returnConfigOptionsToValidate = [];
337 foreach ($configOptionsToValidate as $key =>
$value) {
339 $returnConfigOptionsToValidate[$key] =
$value;
343 return $returnConfigOptionsToValidate;
358 private function askQuestion(
359 InputInterface $input,
363 $validateInline =
false 365 if (
$option instanceof \
Magento\Framework\Setup\Option\SelectConfigOption) {
366 if (
$option->isValueRequired()) {
367 $question =
new ChoiceQuestion(
368 $option->getDescription() .
'? ',
373 $question =
new ChoiceQuestion(
374 $option->getDescription() .
' [optional]? ',
380 if (
$option->isValueRequired()) {
381 $question =
new Question(
382 $option->getDescription() .
'? ',
386 $question =
new Question(
387 $option->getDescription() .
' [optional]? ',
393 $question->setValidator(
function ($answer) use (
$option, $validateInline) {
395 if (
$option instanceof \
Magento\Framework\Setup\Option\SelectConfigOption) {
396 $answer =
$option->getSelectOptions()[$answer];
399 if ($answer ==
null) {
402 $answer = trim($answer);
405 if ($validateInline) {
423 private function validateAdmin(InputInterface $input): array
431 return $this->adminUser->validate($input);
const INPUT_KEY_SAFE_INSTALLER_MODE
const INPUT_KEY_INTERACTIVE_SETUP
const INPUT_KEY_DATA_RESTORE
const SALES_ORDER_INCREMENT_PREFIX_RULE
execute(InputInterface $input, OutputInterface $output)
const INPUT_KEY_DISABLE_MODULES
const INPUT_KEY_CLEANUP_DB
const INPUT_KEY_SALES_ORDER_INCREMENT_PREFIX
const INPUT_KEY_DRY_RUN_MODE
validate(InputInterface $input)
__construct(InstallerFactory $installerFactory, ConfigModel $configModel, InstallStoreConfigurationCommand $userConfig, AdminUserCreateCommand $adminUser)
const INPUT_KEY_ENABLE_MODULES
initialize(InputInterface $input, OutputInterface $output)
const INPUT_KEY_USE_SAMPLE_DATA
const CONVERT_OLD_SCRIPTS_KEY
const INPUT_KEY_INTERACTIVE_SETUP_SHORTCUT