-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
pm_8.inc
132 lines (118 loc) · 4.71 KB
/
pm_8.inc
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/**
* Command callback. Drupal 8 does not support disabled modules.
*
* @param array $args
* Arguments from the command line.
*/
function _drush_pm_disable($args) {
drush_include_engine('drupal', 'environment');
// To be consistent call the environment.inc function which will show the user
// an error.
drush_module_disable($args);
}
/**
* Command callback. Uninstall one or more extensions.
*
* @param array $args
* Arguments from the command line.
*/
function _drush_pm_uninstall($args) {
$extension_info = drush_get_extensions();
// classify $args in themes, modules or unknown.
$modules = array();
$themes = array();
drush_pm_classify_extensions($args, $modules, $themes, $extension_info);
$extensions = array_merge($modules, $themes);
$unknown = array_diff($args, $extensions);
// Discard and set an error for each unknown extension.
foreach ($unknown as $name) {
drush_log('DRUSH_PM_DISABLE_EXTENSION_NOT_FOUND', dt('!extension was not found and will not be uninstalled.', array('!extension' => $name)), 'warning');
}
// Discard extensions that are not installed.
foreach ($extensions as $name) {
if (!$extension_info[$name]->status && $extension_info[$name]->getType() == 'theme') {
unset($themes[$name]);
drush_log(dt('!extension is not installed.', array('!extension' => $name)), 'ok');
}
}
// Discard default theme.
if (!empty($themes)) {
$default_theme = drush_theme_get_default();
if (in_array($default_theme, $themes)) {
unset($themes[$default_theme]);
drush_log(dt('!theme is the default theme and can\'t be disabled.', array('!theme' => $default_theme)), 'ok');
}
}
if (!empty($modules)) {
// Add enabled dependents to the list of modules to uninstall.
$dependents = drush_module_dependents($modules, $extension_info);
$dependents = array_intersect($dependents, drush_module_list());
$modules = array_merge($modules, $dependents);
// Discard required modules.
$required = drush_drupal_required_modules($extension_info);
foreach ($required as $module) {
if (isset($modules[$module])) {
unset($modules[$module]);
$info = $extension_info[$module]->info;
// No message for hidden modules.
if (!isset($info['hidden'])) {
$explanation = !empty($info['explanation']) ? ' ' . dt('Reason: !explanation', array('!explanation' => strip_tags($info['explanation']))) : '';
drush_log(dt('!module is a required module and can\'t be uninstalled.', array('!module' => $module)) . $explanation, 'ok');
}
}
}
}
// Inform the user which extensions will finally be uninstalled.
$extensions = array_merge($modules, $themes);
if (empty($extensions)) {
return drush_log(dt('There were no extensions that could be uninstalled.'), 'ok');
}
else {
drush_print(dt('The following extensions will be uninstalled: !extensions', array('!extensions' => implode(', ', $extensions))));
if(!drush_confirm(dt('Do you really want to continue?'))) {
return drush_user_abort();
}
}
// Disable themes.
if (!empty($themes)) {
drush_theme_disable($themes);
}
// Uninstall modules and pass dependency validation in form submit.
if (!empty($modules)) {
drush_module_uninstall($modules);
}
// Inform the user of final status.
$result_extensions = drush_get_named_extensions_list($extensions);
$problem_extensions = array();
foreach ($result_extensions as $extension) {
if (!$extension->status) {
drush_log(dt('!extension was uninstalled successfully.', array('!extension' => $extension->getName())), 'ok');
}
else {
$problem_extensions[] = $extension->getName();
}
}
if (!empty($problem_extensions)) {
return drush_set_error('DRUSH_PM_UNINSTALL_EXTENSION_ISSUE', dt('There was a problem uninstalling !extension.', array('!extension' => implode(',', $problem_extensions))));
}
}
/**
* Return an array with general info of an extension.
*/
function _drush_pm_info_extension($info) {
$data['extension'] = $info->getName();
$data['project'] = isset($info->info['project'])?$info->info['project']:dt('Unknown');
$data['type'] = $info->getType();
$data['title'] = $info->info['name'];
$data['config'] = isset($info->info['configure']) ? $info->info['configure'] : dt('None');
$data['description'] = $info->info['description'];
$data['version'] = $info->info['version'];
$data['date'] = $info->info['datestamp'] ? format_date($info->info['datestamp'] ?: 0, 'custom', 'Y-m-d') : NULL;
$data['package'] = $info->info['package'];
$data['core'] = $info->info['core'];
$data['php'] = $info->info['php'];
$data['status'] = drush_get_extension_status($info);
$data['path'] = $info->getPath();
return $data;
}