shellProcess = $shellProcess; $this->root = $root; parent::__construct(); } protected function configure() { $this ->setName('module:update') ->setDescription($this->trans('commands.module.update.description')) ->addArgument( 'module', InputArgument::IS_ARRAY, $this->trans('commands.module.update.arguments.module') ) ->addOption( 'composer', null, InputOption::VALUE_NONE, $this->trans('commands.module.update.options.composer') ) ->addOption( 'simulate', null, InputOption::VALUE_NONE, $this->trans('commands.module.update.options.simulate') ); } /** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $composer = $input->getOption('composer'); $module = $input->getArgument('module'); if (!$composer) { $io->error($this->trans('commands.module.update.messages.only-composer')); return 1; } if (!$module) { $module = $this->modulesQuestion($io); $input->setArgument('module', $module); } } /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $modules = $input->getArgument('module'); $composer = $input->getOption('composer'); $simulate = $input->getOption('simulate'); if (!$composer) { $io->error($this->trans('commands.module.update.messages.only-composer')); return 1; } if (!$modules) { $io->error( $this->trans('commands.module.update.messages.missing-module') ); return 1; } if (count($modules) > 1) { $modules = " drupal/" . implode(" drupal/", $modules); } else { $modules = " drupal/" . current($modules); } if ($composer) { // Register composer repository $command = "composer config repositories.drupal composer https://packagist.drupal-composer.org"; $this->shellProcess->exec($command, $this->root); $command = 'composer update ' . $modules . ' --optimize-autoloader --prefer-dist --no-dev --root-reqs '; if ($simulate) { $command .= " --dry-run"; } if ($this->shellProcess->exec($command, $this->root)) { $io->success( sprintf( $this->trans('commands.module.update.messages.composer'), trim($modules) ) ); } } return 0; } }