protected function GenerateConfigurationUpdateCommand::interact in Update helper 8
File
- src/
Command/ GenerateConfigurationUpdateCommand.php, line 184
Class
- GenerateConfigurationUpdateCommand
- Generate configuration update command class.
Namespace
Drupal\update_helper\CommandCode
protected function interact(InputInterface $input, OutputInterface $output) {
$io = new DrupalStyle($input, $output);
$this->site
->loadLegacyFile('/core/includes/update.inc');
$this->site
->loadLegacyFile('/core/includes/schema.inc');
$module = $input
->getOption('module');
$update_number = $input
->getOption('update-n');
$description = $input
->getOption('description');
// TODO: Get information about optional arguments from command definition!
// If at least one required value is requested by interactive mode, then
// request optional values too.
$use_interact_for_optional = empty($module) || empty($update_number) || empty($description);
// Get module name where update will be saved.
if (!$module) {
// TODO: Get only modules that have some configuration changes.
// @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
$module = $this
->moduleQuestion($io);
$input
->setOption('module', $module);
}
// Get Update N number.
$last_update_number = $this
->getLastUpdate($module);
$next_update_number = $last_update_number ? $last_update_number + 1 : 8001;
if (!$update_number) {
$update_number = $io
->ask($this
->trans('commands.generate.configuration.update.questions.update-n'), $next_update_number, function ($update_number) use ($last_update_number) {
if (!is_numeric($update_number)) {
throw new \InvalidArgumentException(sprintf($this
->trans('commands.generate.configuration.update.messages.wrong-update-n'), $update_number));
}
else {
if ($update_number <= $last_update_number) {
throw new \InvalidArgumentException(sprintf($this
->trans('commands.generate.configuration.update.messages.wrong-update-n'), $update_number));
}
return $update_number;
}
});
$input
->setOption('update-n', $update_number);
}
// Get description from interactive mode.
if (!$description) {
$description = $io
->ask($this
->trans('commands.generate.configuration.update.questions.description'), $this
->trans('commands.generate.configuration.update.defaults.description'));
$input
->setOption('description', $description);
}
// Get list of modules that are included in update.
$include_modules = $input
->getOption('include-modules');
if (!$include_modules && $use_interact_for_optional) {
$include_modules = $io
->ask($this
->trans('commands.generate.configuration.update.questions.include-modules'), ' ');
$input
->setOption('include-modules', trim($include_modules));
}
// Get additional options provided by other modules.
$event = new CommandInteractEvent($this, $input, $io);
$this->eventDispatcher
->dispatch(UpdateHelperEvents::COMMAND_GCU_INTERACT, $event);
}