site = $site; $this->validator = $validator; $this->moduleInstaller = $moduleInstaller; $this->drupalApi = $drupalApi; $this->extensionManager = $extensionManager; $this->appRoot = $appRoot; $this->chainQueue = $chainQueue; parent::__construct(); } /** * {@inheritdoc} */ protected function configure() { $this ->setName('module:install') ->setDescription($this->trans('commands.module.install.description')) ->addArgument( 'module', InputArgument::IS_ARRAY, $this->trans('commands.module.install.arguments.module') ) ->addOption( 'latest', null, InputOption::VALUE_NONE, $this->trans('commands.module.install.options.latest') ) ->addOption( 'composer', null, InputOption::VALUE_NONE, $this->trans('commands.module.uninstall.options.composer') ) ->setAliases(['moi']); } /** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $module = $input->getArgument('module'); if (!$module) { $module = $this->modulesQuestion(); $input->setArgument('module', $module); } } /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $module = $input->getArgument('module'); $latest = $input->getOption('latest'); $composer = $input->getOption('composer'); $this->site->loadLegacyFile('/core/includes/bootstrap.inc'); // check module's requirements $this->moduleRequirement($module); if ($composer) { foreach ($module as $moduleItem) { $command = sprintf( 'composer show drupal/%s ', $moduleItem ); $processBuilder = new ProcessBuilder([]); $processBuilder->setWorkingDirectory($this->appRoot); $processBuilder->setArguments(explode(" ", $command)); $process = $processBuilder->getProcess(); $process->setTty('true'); $process->run(); if ($process->isSuccessful()) { $this->getIo()->info( sprintf( $this->trans('commands.module.install.messages.download-with-composer'), $moduleItem ) ); } else { $this->getIo()->error( sprintf( $this->trans('commands.module.install.messages.not-installed-with-composer'), $moduleItem ) ); throw new \RuntimeException($process->getErrorOutput()); } } $unInstalledModules = $module; } else { $resultList = $this->downloadModules($module, $latest); $invalidModules = $resultList['invalid']; $unInstalledModules = $resultList['uninstalled']; if ($invalidModules) { foreach ($invalidModules as $invalidModule) { unset($module[array_search($invalidModule, $module)]); $this->getIo()->error( sprintf( $this->trans('commands.module.install.messages.invalid-name'), $invalidModule ) ); } } if (!$unInstalledModules) { $this->getIo()->warning($this->trans('commands.module.install.messages.nothing')); return 0; } } try { $this->getIo()->comment( sprintf( $this->trans('commands.module.install.messages.installing'), implode(', ', $unInstalledModules) ) ); drupal_static_reset('system_rebuild_module_data'); $this->moduleInstaller->install($unInstalledModules, true); $this->getIo()->success( sprintf( $this->trans('commands.module.install.messages.success'), implode(', ', $unInstalledModules) ) ); } catch (\Exception $e) { $this->getIo()->error($e->getMessage()); return 1; } $this->site->removeCachedServicesFile(); $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); } }