pm.inc

  1. 8.0.x commands/core/drupal/pm.inc
  2. 7.x commands/core/drupal/pm.inc
  3. master commands/core/drupal/pm.inc

Functions

Namesort ascending Description
_drush_pm_uninstall Command callback. Uninstall one or more modules.
_drush_pm_disable Command callback. Disable one or more extensions.

File

commands/core/drupal/pm.inc
View source
  1. <?php
  2. use Drush\Log\LogLevel;
  3. /**
  4. * Command callback. Disable one or more extensions.
  5. */
  6. function _drush_pm_disable($args) {
  7. $extension_info = drush_get_extensions();
  8. // classify $args in themes, modules or unknown.
  9. $modules = array();
  10. $themes = array();
  11. drush_pm_classify_extensions($args, $modules, $themes, $extension_info);
  12. $extensions = array_merge($modules, $themes);
  13. $unknown = array_diff($args, $extensions);
  14. // Discard and set an error for each unknown extension.
  15. foreach ($unknown as $name) {
  16. drush_log('DRUSH_PM_ENABLE_EXTENSION_NOT_FOUND', dt('!extension was not found and will not be disabled.', array('!extension' => $name)), LogLevel::WARNING);
  17. }
  18. // Discard already disabled extensions.
  19. foreach ($extensions as $name) {
  20. if (!$extension_info[$name]->status) {
  21. if ($extension_info[$name]->type == 'module') {
  22. unset($modules[$name]);
  23. }
  24. else {
  25. unset($themes[$name]);
  26. }
  27. drush_log(dt('!extension is already disabled.', array('!extension' => $name)), LogLevel::OK);
  28. }
  29. }
  30. // Discard default theme.
  31. if (!empty($themes)) {
  32. $default_theme = drush_theme_get_default();
  33. if (in_array($default_theme, $themes)) {
  34. unset($themes[$default_theme]);
  35. drush_log(dt('!theme is the default theme and can\'t be disabled.', array('!theme' => $default_theme)), LogLevel::OK);
  36. }
  37. }
  38. if (!empty($modules)) {
  39. // Add enabled dependents to the list of modules to disable.
  40. $dependents = drush_module_dependents($modules, $extension_info);
  41. $dependents = array_intersect($dependents, drush_module_list());
  42. $modules = array_merge($modules, $dependents);
  43. // Discard required modules.
  44. $required = drush_drupal_required_modules($extension_info);
  45. foreach ($required as $module) {
  46. if (isset($modules[$module])) {
  47. unset($modules[$module]);
  48. $info = $extension_info[$module]->info;
  49. // No message for hidden modules.
  50. if (!isset($info['hidden'])) {
  51. $explanation = !empty($info['explanation']) ? ' ' . dt('Reason: !explanation.', array('!explanation' => strip_tags($info['explanation']))) : '';
  52. drush_log(dt('!module is a required module and can\'t be disabled.', array('!module' => $module)) . $explanation, LogLevel::OK);
  53. }
  54. }
  55. }
  56. }
  57. // Inform the user which extensions will finally be disabled.
  58. $extensions = array_merge($modules, $themes);
  59. if (empty($extensions)) {
  60. return drush_log(dt('There were no extensions that could be disabled.'), LogLevel::OK);
  61. }
  62. else {
  63. drush_print(dt('The following extensions will be disabled: !extensions', array('!extensions' => implode(', ', $extensions))));
  64. if(!drush_confirm(dt('Do you really want to continue?'))) {
  65. return drush_user_abort();
  66. }
  67. }
  68. // Disable themes.
  69. if (!empty($themes)) {
  70. drush_theme_disable($themes);
  71. }
  72. // Disable modules and pass dependency validation in form submit.
  73. if (!empty($modules)) {
  74. drush_module_disable($modules);
  75. }
  76. // Inform the user of final status.
  77. $result_extensions = drush_get_named_extensions_list($extensions);
  78. $problem_extensions = array();
  79. foreach ($result_extensions as $extension) {
  80. if (!$extension->status) {
  81. drush_log(dt('!extension was disabled successfully.', array('!extension' => $extension->name)), LogLevel::OK);
  82. }
  83. else {
  84. $problem_extensions[] = $extension->name;
  85. }
  86. }
  87. if (!empty($problem_extensions)) {
  88. return drush_set_error('DRUSH_PM_DISABLE_EXTENSION_ISSUE', dt('There was a problem disabling !extension.', array('!extension' => implode(',', $problem_extensions))));
  89. }
  90. }
  91. /**
  92. * Command callback. Uninstall one or more modules.
  93. */
  94. function _drush_pm_uninstall($modules) {
  95. drush_include_engine('drupal', 'environment');
  96. $module_info = drush_get_modules();
  97. $required = drush_drupal_required_modules($module_info);
  98. // Discards modules which are enabled, not found or already uninstalled.
  99. foreach ($modules as $key => $module) {
  100. if (!isset($module_info[$module])) {
  101. // The module does not exist in the system.
  102. unset($modules[$key]);
  103. drush_log(dt('Module !module was not found and will not be uninstalled.', array('!module' => $module)), LogLevel::WARNING);
  104. }
  105. else if ($module_info[$module]->status) {
  106. // The module is enabled.
  107. unset($modules[$key]);
  108. drush_log(dt('!module is not disabled. Use `pm-disable` command before `pm-uninstall`.', array('!module' => $module)), LogLevel::WARNING);
  109. }
  110. else if ($module_info[$module]->schema_version == -1) { // SCHEMA_UNINSTALLED
  111. // The module is uninstalled.
  112. unset($modules[$key]);
  113. drush_log(dt('!module is already uninstalled.', array('!module' => $module)), LogLevel::OK);
  114. }
  115. else {
  116. $dependents = array();
  117. foreach (drush_module_dependents(array($module), $module_info) as $dependent) {
  118. if (!in_array($dependent, $required) && ($module_info[$dependent]->schema_version != -1)) {
  119. $dependents[] = $dependent;
  120. }
  121. }
  122. if (count($dependents)) {
  123. drush_log(dt('To uninstall !module, the following modules must be uninstalled first: !required', array('!module' => $module, '!required' => implode(', ', $dependents))), LogLevel::ERROR);
  124. unset($modules[$key]);
  125. }
  126. }
  127. }
  128. // Inform the user which modules will finally be uninstalled.
  129. if (empty($modules)) {
  130. return drush_log(dt('There were no modules that could be uninstalled.'), LogLevel::OK);
  131. }
  132. else {
  133. drush_print(dt('The following modules will be uninstalled: !modules', array('!modules' => implode(', ', $modules))));
  134. if(!drush_confirm(dt('Do you really want to continue?'))) {
  135. return drush_user_abort();
  136. }
  137. }
  138. // Uninstall the modules.
  139. drush_module_uninstall($modules);
  140. // Inform the user of final status.
  141. foreach ($modules as $module) {
  142. drush_log(dt('!module was successfully uninstalled.', array('!module' => $module)), LogLevel::OK);
  143. }
  144. }