/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $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()) { $io->info(sprintf('Module %s was downloaded with Composer.', $moduleItem)); } else { $io->error(sprintf('Module %s seems not to be installed with Composer. Halting.', $moduleItem)); throw new \RuntimeException($process->getErrorOutput()); return 0; } } $unInstalledModules = $module; } else { $resultList = $this->downloadModules($io, $module, $latest); $invalidModules = $resultList['invalid']; $unInstalledModules = $resultList['uninstalled']; if ($invalidModules) { foreach ($invalidModules as $invalidModule) { unset($module[array_search($invalidModule, $module)]); $io->error(sprintf('Invalid module name: %s', $invalidModule)); } } if (!$unInstalledModules) { $io->warning($this->trans('commands.module.install.messages.nothing')); return 0; } } try { $io->comment(sprintf($this->trans('commands.module.install.messages.installing'), implode(', ', $unInstalledModules))); drupal_static_reset('system_rebuild_module_data'); $this->moduleInstaller->install($unInstalledModules, true); $io->success(sprintf($this->trans('commands.module.install.messages.success'), implode(', ', $unInstalledModules))); } catch (\Exception $e) { $io->error($e->getMessage()); return 1; } $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $composer = $input->getOption('composer'); $module = $input->getArgument('module'); $this->site->loadLegacyFile('/core/modules/system/system.module'); $coreExtension = $this->configFactory->getEditable('core.extension'); // Get info about modules available $moduleData = system_rebuild_module_data(); $moduleList = array_combine($module, $module); if ($composer) { //@TODO: check with Composer if the module is previously required in composer.json! foreach ($module as $moduleItem) { $command = sprintf('composer remove drupal/%s ', $moduleItem); $shellProcess = $this->get('shell_process'); if ($shellProcess->exec($command)) { $io->success(sprintf($this->trans('commands.module.uninstall.messages.composer-success'), $moduleItem)); } } } if ($missingModules = array_diff_key($moduleList, $moduleData)) { $io->error(sprintf($this->trans('commands.module.uninstall.messages.missing'), implode(', ', $module), implode(', ', $missingModules))); return 1; } $installedModules = $coreExtension->get('module') ?: array(); if (!($moduleList = array_intersect_key($moduleList, $installedModules))) { $io->info($this->trans('commands.module.uninstall.messages.nothing')); return 0; } if (!($force = $input->getOption('force'))) { $dependencies = []; while (list($module) = each($moduleList)) { foreach (array_keys($moduleData[$module]->required_by) as $dependency) { if (isset($installedModules[$dependency]) && !isset($moduleList[$dependency]) && $dependency != $profile) { $dependencies[] = $dependency; } } } if (!empty($dependencies)) { $io->error(sprintf($this->trans('commands.module.uninstall.messages.dependents'), implode('", "', $moduleList), implode(', ', $dependencies))); return 1; } } try { $this->moduleInstaller->uninstall($moduleList); $io->info(sprintf($this->trans('commands.module.uninstall.messages.success'), implode(', ', $moduleList))); $io->comment(sprintf($this->trans('commands.module.uninstall.messages.composer-success'), implode(', ', $moduleList), false)); } catch (\Exception $e) { $io->error($e->getMessage()); return 1; } $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $module = $input->getArgument('module'); $unInstalledDependencies = $this->calculateDependencies((array) $module); if (!$unInstalledDependencies) { $io->warning($this->trans('commands.module.install.dependencies.messages.no-depencies')); return 0; } try { $io->comment(sprintf($this->trans('commands.module.install.dependencies.messages.installing'), implode(', ', $unInstalledDependencies))); drupal_static_reset('system_rebuild_module_data'); $this->moduleInstaller->install($unInstalledDependencies, true); $io->success(sprintf($this->trans('commands.module.install.dependencies.messages.success'), implode(', ', $unInstalledDependencies))); } catch (\Exception $e) { $io->error($e->getMessage()); return 1; } $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); }