5 * Contains \Drupal\Console\Command\Module\InstallCommand.
8 namespace Drupal\Console\Command\Module;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputOption;
12 use Symfony\Component\Console\Input\InputInterface;
13 use Symfony\Component\Console\Output\OutputInterface;
14 use Symfony\Component\Process\ProcessBuilder;
15 use Drupal\Console\Core\Command\Command;
16 use Drupal\Console\Command\Shared\ProjectDownloadTrait;
17 use Drupal\Console\Command\Shared\ModuleTrait;
18 use Drupal\Console\Utils\Site;
19 use Drupal\Console\Utils\Validator;
20 use Drupal\Core\Extension\ModuleInstallerInterface;
21 use Drupal\Console\Utils\DrupalApi;
22 use Drupal\Console\Extension\Manager;
23 use Drupal\Console\Core\Utils\ChainQueue;
26 * Class InstallCommand
28 * @package Drupal\Console\Command\Module
30 class InstallCommand extends Command
32 use ProjectDownloadTrait;
46 * @var ModuleInstaller
48 protected $moduleInstaller;
58 protected $extensionManager;
68 protected $chainQueue;
71 * InstallCommand constructor.
74 * @param Validator $validator
75 * @param ModuleInstaller $moduleInstaller
76 * @param DrupalApi $drupalApi
77 * @param Manager $extensionManager
79 * @param ChainQueue $chainQueue
81 public function __construct(
84 ModuleInstallerInterface $moduleInstaller,
86 Manager $extensionManager,
88 ChainQueue $chainQueue
91 $this->validator = $validator;
92 $this->moduleInstaller = $moduleInstaller;
93 $this->drupalApi = $drupalApi;
94 $this->extensionManager = $extensionManager;
95 $this->appRoot = $appRoot;
96 $this->chainQueue = $chainQueue;
97 parent::__construct();
103 protected function configure()
106 ->setName('module:install')
107 ->setDescription($this->trans('commands.module.install.description'))
110 InputArgument::IS_ARRAY,
111 $this->trans('commands.module.install.arguments.module')
116 InputOption::VALUE_NONE,
117 $this->trans('commands.module.install.options.latest')
122 InputOption::VALUE_NONE,
123 $this->trans('commands.module.uninstall.options.composer')
125 ->setAliases(['moi']);
131 protected function interact(InputInterface $input, OutputInterface $output)
133 $module = $input->getArgument('module');
135 $module = $this->modulesQuestion();
136 $input->setArgument('module', $module);
143 protected function execute(InputInterface $input, OutputInterface $output)
145 $module = $input->getArgument('module');
146 $latest = $input->getOption('latest');
147 $composer = $input->getOption('composer');
149 $this->site->loadLegacyFile('/core/includes/bootstrap.inc');
151 // check module's requirements
152 $this->moduleRequirement($module);
155 foreach ($module as $moduleItem) {
157 'composer show drupal/%s ',
161 $processBuilder = new ProcessBuilder([]);
162 $processBuilder->setWorkingDirectory($this->appRoot);
163 $processBuilder->setArguments(explode(" ", $command));
164 $process = $processBuilder->getProcess();
165 $process->setTty('true');
168 if ($process->isSuccessful()) {
169 $this->getIo()->info(
171 $this->trans('commands.module.install.messages.download-with-composer'),
176 $this->getIo()->error(
178 $this->trans('commands.module.install.messages.not-installed-with-composer'),
182 throw new \RuntimeException($process->getErrorOutput());
186 $unInstalledModules = $module;
188 $resultList = $this->downloadModules($module, $latest);
190 $invalidModules = $resultList['invalid'];
191 $unInstalledModules = $resultList['uninstalled'];
193 if ($invalidModules) {
194 foreach ($invalidModules as $invalidModule) {
195 unset($module[array_search($invalidModule, $module)]);
196 $this->getIo()->error(
198 $this->trans('commands.module.install.messages.invalid-name'),
205 if (!$unInstalledModules) {
206 $this->getIo()->warning($this->trans('commands.module.install.messages.nothing'));
213 $this->getIo()->comment(
215 $this->trans('commands.module.install.messages.installing'),
216 implode(', ', $unInstalledModules)
220 drupal_static_reset('system_rebuild_module_data');
222 $this->moduleInstaller->install($unInstalledModules, true);
223 $this->getIo()->success(
225 $this->trans('commands.module.install.messages.success'),
226 implode(', ', $unInstalledModules)
229 } catch (\Exception $e) {
230 $this->getIo()->error($e->getMessage());
235 $this->site->removeCachedServicesFile();
236 $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);