configModel = $configModel; $this->moduleList = $moduleList; $this->deploymentConfig = $deploymentConfig; parent::__construct(); } /** * Initialization of the command * * @return void */ protected function configure() { $options = $this->configModel->getAvailableOptions(); $this->setName('setup:config:set') ->setDescription('Creates or modifies the deployment configuration') ->setDefinition($options); parent::configure(); } /** * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { $inputOptions = $input->getOptions(); $optionCollection = $this->configModel->getAvailableOptions(); $commandOptions = []; $optionsWithDefaultValues = []; foreach ($optionCollection as $option) { $commandOptions[$option->getName()] = false; $currentValue = $this->deploymentConfig->get($option->getConfigPath()); if (($currentValue !== null) && ($inputOptions[$option->getName()] !== null)) { $dialog = $this->getHelperSet()->get('question'); $question = new Question( 'Overwrite the existing configuration for ' . $option->getName() . '?[Y/n]', 'y' ); if (strtolower($dialog->ask($input, $output, $question)) !== 'y') { $inputOptions[$option->getName()] = null; } } if ($option->getDefault() === $inputOptions[$option->getName()] && $inputOptions[$option->getName()] !== null ) { $optionsWithDefaultValues[] = $option->getName(); } } $inputOptions = array_filter( $inputOptions, function ($value) { return $value !== null; } ); $optionsToChange = array_intersect(array_keys($inputOptions), array_keys($commandOptions)); $optionsToChange = array_diff($optionsToChange, [ConfigOptionsListConstants::INPUT_KEY_SKIP_DB_VALIDATION]); $this->configModel->process($inputOptions); $optionsWithDefaultValues = array_diff( $optionsWithDefaultValues, [ConfigOptionsListConstants::INPUT_KEY_SKIP_DB_VALIDATION] ); if (count($optionsWithDefaultValues) > 0) { $defaultValuesMessage = implode(', ', $optionsWithDefaultValues); $output->writeln( 'We saved default values for these options: ' . $defaultValuesMessage . '.' ); } else { if (count($optionsToChange) > 0) { $output->writeln('You saved the new configuration.'); } else { $output->writeln('You made no changes to the configuration.'); } } return \Magento\Framework\Console\Cli::RETURN_SUCCESS; } /** * @inheritdoc */ protected function initialize(InputInterface $input, OutputInterface $output) { $inputOptions = $input->getOptions(); $errors = $this->configModel->validate($inputOptions); if (!empty($errors)) { foreach ($errors as $error) { $output->writeln("$error"); } throw new \InvalidArgumentException('Parameter validation failed'); } } }