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\Console\Command\Command;
17 use Drupal\Console\Command\Shared\ProjectDownloadTrait;
18 use Drupal\Console\Command\Shared\ModuleTrait;
19 use Drupal\Console\Core\Style\DrupalStyle;
20 use Drupal\Console\Utils\Site;
21 use Drupal\Console\Utils\Validator;
22 use Drupal\Core\ProxyClass\Extension\ModuleInstaller;
23 use Drupal\Console\Utils\DrupalApi;
24 use Drupal\Console\Extension\Manager;
25 use Drupal\Console\Core\Utils\ChainQueue;
28 * Class InstallCommand
30 * @package Drupal\Console\Command\Module
32 class InstallCommand extends Command
35 use ProjectDownloadTrait;
49 * @var ModuleInstaller
51 protected $moduleInstaller;
61 protected $extensionManager;
71 protected $chainQueue;
74 * InstallCommand constructor.
77 * @param Validator $validator
78 * @param ModuleInstaller $moduleInstaller
79 * @param DrupalApi $drupalApi
80 * @param Manager $extensionManager
82 * @param ChainQueue $chainQueue
84 public function __construct(
87 ModuleInstaller $moduleInstaller,
89 Manager $extensionManager,
91 ChainQueue $chainQueue
94 $this->validator = $validator;
95 $this->moduleInstaller = $moduleInstaller;
96 $this->drupalApi = $drupalApi;
97 $this->extensionManager = $extensionManager;
98 $this->appRoot = $appRoot;
99 $this->chainQueue = $chainQueue;
100 parent::__construct();
106 protected function configure()
109 ->setName('module:install')
110 ->setDescription($this->trans('commands.module.install.description'))
113 InputArgument::IS_ARRAY,
114 $this->trans('commands.module.install.arguments.module')
119 InputOption::VALUE_NONE,
120 $this->trans('commands.module.install.options.latest')
125 InputOption::VALUE_NONE,
126 $this->trans('commands.module.uninstall.options.composer')
133 protected function interact(InputInterface $input, OutputInterface $output)
135 $io = new DrupalStyle($input, $output);
137 $module = $input->getArgument('module');
139 $module = $this->modulesQuestion($io);
140 $input->setArgument('module', $module);
147 protected function execute(InputInterface $input, OutputInterface $output)
149 $io = new DrupalStyle($input, $output);
151 $module = $input->getArgument('module');
152 $latest = $input->getOption('latest');
153 $composer = $input->getOption('composer');
155 $this->site->loadLegacyFile('/core/includes/bootstrap.inc');
157 // check module's requirements
158 $this->moduleRequirement($module, $io);
161 foreach ($module as $moduleItem) {
163 'composer show drupal/%s ',
167 $processBuilder = new ProcessBuilder([]);
168 $processBuilder->setWorkingDirectory($this->appRoot);
169 $processBuilder->setArguments(explode(" ", $command));
170 $process = $processBuilder->getProcess();
171 $process->setTty('true');
174 if ($process->isSuccessful()) {
177 'Module %s was downloaded with Composer.',
184 'Module %s seems not to be installed with Composer. Halting.',
188 throw new \RuntimeException($process->getErrorOutput());
192 $unInstalledModules = $module;
194 $resultList = $this->downloadModules($io, $module, $latest);
196 $invalidModules = $resultList['invalid'];
197 $unInstalledModules = $resultList['uninstalled'];
199 if ($invalidModules) {
200 foreach ($invalidModules as $invalidModule) {
201 unset($module[array_search($invalidModule, $module)]);
204 'Invalid module name: %s',
211 if (!$unInstalledModules) {
212 $io->warning($this->trans('commands.module.install.messages.nothing'));
221 $this->trans('commands.module.install.messages.installing'),
222 implode(', ', $unInstalledModules)
226 drupal_static_reset('system_rebuild_module_data');
228 $this->moduleInstaller->install($unInstalledModules, true);
231 $this->trans('commands.module.install.messages.success'),
232 implode(', ', $unInstalledModules)
235 } catch (\Exception $e) {
236 $io->error($e->getMessage());
241 $this->site->removeCachedServicesFile();
242 $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);