5 * Contains \Drupal\Console\Command\Module\UninstallCommand.
8 namespace Drupal\Console\Command\Module;
10 use Drupal\Console\Core\Command\Shared\CommandTrait;
11 use Drupal\Console\Extension\Manager;
12 use Symfony\Component\Console\Input\InputArgument;
13 use Symfony\Component\Console\Input\InputInterface;
14 use Symfony\Component\Console\Input\InputOption;
15 use Symfony\Component\Console\Output\OutputInterface;
16 use Symfony\Component\Console\Command\Command;
17 use Drupal\Console\Command\Shared\ProjectDownloadTrait;
18 use Drupal\Console\Core\Style\DrupalStyle;
19 use Drupal\Console\Utils\Site;
20 use Drupal\Core\ProxyClass\Extension\ModuleInstaller;
21 use Drupal\Console\Core\Utils\ChainQueue;
22 use Drupal\Core\Config\ConfigFactory;
24 class UninstallCommand extends Command
27 use ProjectDownloadTrait;
35 * @var ModuleInstaller
37 protected $moduleInstaller;
42 protected $chainQueue;
47 protected $configFactory;
52 protected $extensionManager;
55 * InstallCommand constructor.
58 * @param ModuleInstaller $moduleInstaller
59 * @param ChainQueue $chainQueue
60 * @param ConfigFactory $configFactory
61 * @param Manager $extensionManager
63 public function __construct(
65 ModuleInstaller $moduleInstaller,
66 ChainQueue $chainQueue,
67 ConfigFactory $configFactory,
68 Manager $extensionManager
71 $this->moduleInstaller = $moduleInstaller;
72 $this->chainQueue = $chainQueue;
73 $this->configFactory = $configFactory;
74 $this->extensionManager = $extensionManager;
75 parent::__construct();
81 protected function configure()
84 ->setName('module:uninstall')
85 ->setDescription($this->trans('commands.module.uninstall.description'))
88 InputArgument::IS_ARRAY,
89 $this->trans('commands.module.uninstall.questions.module')
94 InputOption::VALUE_NONE,
95 $this->trans('commands.module.uninstall.options.force')
100 InputOption::VALUE_NONE,
101 $this->trans('commands.module.uninstall.options.composer')
107 protected function interact(InputInterface $input, OutputInterface $output)
109 $io = new DrupalStyle($input, $output);
110 $module = $input->getArgument('module');
113 $module = $this->modulesUninstallQuestion($io);
114 $input->setArgument('module', $module);
120 protected function execute(InputInterface $input, OutputInterface $output)
122 $io = new DrupalStyle($input, $output);
123 $composer = $input->getOption('composer');
124 $module = $input->getArgument('module');
126 $this->site->loadLegacyFile('/core/modules/system/system.module');
128 $coreExtension = $this->configFactory->getEditable('core.extension');
130 // Get info about modules available
131 $moduleData = system_rebuild_module_data();
132 $moduleList = array_combine($module, $module);
135 //@TODO: check with Composer if the module is previously required in composer.json!
136 foreach ($module as $moduleItem) {
138 'composer remove drupal/%s ',
142 $shellProcess = $this->get('shell_process');
143 if ($shellProcess->exec($command)) {
146 $this->trans('commands.module.uninstall.messages.composer-success'),
154 if ($missingModules = array_diff_key($moduleList, $moduleData)) {
157 $this->trans('commands.module.uninstall.messages.missing'),
158 implode(', ', $module),
159 implode(', ', $missingModules)
166 $installedModules = $coreExtension->get('module') ?: [];
167 if (!$moduleList = array_intersect_key($moduleList, $installedModules)) {
168 $io->info($this->trans('commands.module.uninstall.messages.nothing'));
173 if (!$force = $input->getOption('force')) {
175 while (list($module) = each($moduleList)) {
176 foreach (array_keys($moduleData[$module]->required_by) as $dependency) {
177 if (isset($installedModules[$dependency]) && !isset($moduleList[$dependency]) && $dependency != $profile) {
178 $dependencies[] = $dependency;
183 if (!empty($dependencies)) {
186 $this->trans('commands.module.uninstall.messages.dependents'),
187 implode('", "', $moduleList),
188 implode(', ', $dependencies)
197 $this->moduleInstaller->uninstall($moduleList);
201 $this->trans('commands.module.uninstall.messages.success'),
202 implode(', ', $moduleList)
208 $this->trans('commands.module.uninstall.messages.composer-success'),
209 implode(', ', $moduleList),
213 } catch (\Exception $e) {
214 $io->error($e->getMessage());
219 $this->site->removeCachedServicesFile();
220 $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);