forked from hechoendrupal/drupal-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleUninstallCommand.php
More file actions
85 lines (67 loc) · 3.06 KB
/
Copy pathModuleUninstallCommand.php
File metadata and controls
85 lines (67 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* @file
* Contains \Drupal\AppConsole\Command\ModuleUninstallCommand.
*/
namespace Drupal\AppConsole\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ModuleUninstallCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('module:uninstall')
->setDescription($this->trans('commands.module.install.description'))
->addArgument('module', InputArgument::REQUIRED, $this->trans('commands.module.install.options.module'));
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$extension_config = $this->getConfigFactory()->getEditable('core.extension');
$moduleInstaller = $this->getModuleInstaller();
// Get info about modules available
$module_data = system_rebuild_module_data();
$module = $input->getArgument('module');
$modules = array_filter(array_map('trim', explode(",", $module)));
$module_list = array_combine($modules, $modules);
// Determine if some module request is missing
if ($missing_modules = array_diff_key($module_list, $module_data)) {
$output->writeln('[+] <error>' . sprintf($this->trans('commands.module.uninstall.messages.missing'),
implode(", ", $modules), implode(", ", $missing_modules)) . '</error>');
return true;
}
// Only process currently installed modules.
$installed_modules = $extension_config->get('module') ?: array();
if (!$module_list = array_intersect_key($module_list, $installed_modules)) {
$output->writeln('[+] <info>' . $this->trans('commands.module.uninstall.messages.nothing') . '</info>');
return true;
}
// Calculate $dependents
$dependents = array();
while (list($module) = each($module_list)) {
foreach (array_keys($module_data[$module]->required_by) as $dependent) {
// Skip already uninstalled modules.
if (isset($installed_modules[$dependent]) && !isset($module_list[$dependent]) && $dependent != $profile) {
$dependents[] = $dependent;
}
}
}
// Error if there are missing dependencies
if (!empty($dependents)) {
$output->writeln('[+] <error>' . sprintf($this->trans('commands.module.uninstall.messages.dependents'),
implode(", ", $modules), implode(", ", $dependents)) . '</error>');
return true;
}
// Installing modules
try {
// Install the modules.
$moduleInstaller->uninstall($module_list);
$output->writeln('[+] <info>' . sprintf($this->trans('commands.module.uninstall.messages.success'),
implode(", ", $modules)) . '</info>');
} catch (\Exception $e) {
$output->writeln('[+] <error>' . $e->getMessage() . '</error>');
return;
}
}
}