5 * Contains \Drupal\Console\Command\Module\InstallCommand.
8 namespace Drupal\Console\Command\Module;
10 use Drupal\Console\Core\Command\Shared\CommandTrait;
11 use Symfony\Component\Console\Input\InputArgument;
12 use Symfony\Component\Console\Input\InputOption;
13 use Symfony\Component\Console\Input\InputInterface;
14 use Symfony\Component\Console\Output\OutputInterface;
15 use Symfony\Component\Process\ProcessBuilder;
16 use Symfony\Component\Process\Exception\ProcessFailedException;
17 use Symfony\Component\Console\Command\Command;
18 use Drupal\Console\Command\Shared\ProjectDownloadTrait;
19 use Drupal\Console\Command\Shared\ModuleTrait;
20 use Drupal\Console\Core\Style\DrupalStyle;
21 use Drupal\Console\Utils\Site;
22 use Drupal\Console\Utils\Validator;
23 use Drupal\Core\ProxyClass\Extension\ModuleInstaller;
24 use Drupal\Console\Utils\DrupalApi;
25 use Drupal\Console\Extension\Manager;
26 use Drupal\Console\Core\Utils\ChainQueue;
29 * Class InstallCommand
31 * @package Drupal\Console\Command\Module
33 class InstallCommand extends Command
36 use ProjectDownloadTrait;
50 * @var ModuleInstaller
52 protected $moduleInstaller;
62 protected $extensionManager;
72 protected $chainQueue;
75 * InstallCommand constructor.
78 * @param Validator $validator
79 * @param ModuleInstaller $moduleInstaller
80 * @param DrupalApi $drupalApi
81 * @param Manager $extensionManager
83 * @param ChainQueue $chainQueue
85 public function __construct(
88 ModuleInstaller $moduleInstaller,
90 Manager $extensionManager,
92 ChainQueue $chainQueue
95 $this->validator = $validator;
96 $this->moduleInstaller = $moduleInstaller;
97 $this->drupalApi = $drupalApi;
98 $this->extensionManager = $extensionManager;
99 $this->appRoot = $appRoot;
100 $this->chainQueue = $chainQueue;
101 parent::__construct();
107 protected function configure()
110 ->setName('module:install')
111 ->setDescription($this->trans('commands.module.install.description'))
114 InputArgument::IS_ARRAY,
115 $this->trans('commands.module.install.arguments.module')
120 InputOption::VALUE_NONE,
121 $this->trans('commands.module.install.options.latest')
126 InputOption::VALUE_NONE,
127 $this->trans('commands.module.uninstall.options.composer')
134 protected function interact(InputInterface $input, OutputInterface $output)
136 $io = new DrupalStyle($input, $output);
138 $module = $input->getArgument('module');
140 $module = $this->modulesQuestion($io);
141 $input->setArgument('module', $module);
148 protected function execute(InputInterface $input, OutputInterface $output)
150 $io = new DrupalStyle($input, $output);
152 $module = $input->getArgument('module');
153 $latest = $input->getOption('latest');
154 $composer = $input->getOption('composer');
156 $this->site->loadLegacyFile('/core/includes/bootstrap.inc');
158 // check module's requirements
159 $this->moduleRequirement($module, $io);
162 foreach ($module as $moduleItem) {
164 'composer show drupal/%s ',
168 $processBuilder = new ProcessBuilder([]);
169 $processBuilder->setWorkingDirectory($this->appRoot);
170 $processBuilder->setArguments(explode(" ", $command));
171 $process = $processBuilder->getProcess();
172 $process->setTty('true');
175 if ($process->isSuccessful()) {
178 'Module %s was downloaded with Composer.',
185 'Module %s seems not to be installed with Composer. Halting.',
189 throw new \RuntimeException($process->getErrorOutput());
195 $unInstalledModules = $module;
197 $resultList = $this->downloadModules($io, $module, $latest);
199 $invalidModules = $resultList['invalid'];
200 $unInstalledModules = $resultList['uninstalled'];
202 if ($invalidModules) {
203 foreach ($invalidModules as $invalidModule) {
204 unset($module[array_search($invalidModule, $module)]);
207 'Invalid module name: %s',
214 if (!$unInstalledModules) {
215 $io->warning($this->trans('commands.module.install.messages.nothing'));
224 $this->trans('commands.module.install.messages.installing'),
225 implode(', ', $unInstalledModules)
229 drupal_static_reset('system_rebuild_module_data');
231 $this->moduleInstaller->install($unInstalledModules, true);
234 $this->trans('commands.module.install.messages.success'),
235 implode(', ', $unInstalledModules)
238 } catch (\Exception $e) {
239 $io->error($e->getMessage());
244 $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);