pm_8.inc

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

Functions

Namesort descending Description
_drush_pm_disable Command callback. Drupal 8 does not support disabled modules.
_drush_pm_uninstall Command callback. Uninstall one or more extensions.

File

commands/core/drupal/pm_8.inc
View source
  1. <?php
  2. use Drush\Log\LogLevel;
  3. /**
  4. * Command callback. Drupal 8 does not support disabled modules.
  5. *
  6. * @param array $args
  7. * Arguments from the command line.
  8. */
  9. function _drush_pm_disable($args) {
  10. drush_include_engine('drupal', 'environment');
  11. // To be consistent call the environment.inc function which will show the user
  12. // an error.
  13. drush_module_disable($args);
  14. }
  15. /**
  16. * Command callback. Uninstall one or more extensions.
  17. *
  18. * @param array $args
  19. * Arguments from the command line.
  20. */
  21. function _drush_pm_uninstall($extensions) {
  22. $extension_info = drush_get_extensions();
  23. $required = drush_drupal_required_modules($extension_info);
  24. // Discards extensions which are enabled, not found or already uninstalled.
  25. $extensions = array_combine($extensions, $extensions);
  26. foreach ($extensions as $extension) {
  27. if (!isset($extension_info[$extension])) {
  28. unset($extensions[$extension]);
  29. drush_log(dt('Extension !extension was not found and will not be uninstalled.', array('!extension' => $extension)), LogLevel::WARNING);
  30. }
  31. elseif (in_array($extension, $required)) {
  32. unset($extensions[$extension]);
  33. $info = $extension_info[$extension]->info;
  34. $explanation = !empty($info['explanation']) ? ' ' . dt('Reason: !explanation.', array('!explanation' => strip_tags($info['explanation']))) : '';
  35. drush_log(dt('!extension is a required extension and can\'t be uninstalled.', array('!extension' => $extension)) . $explanation, LogLevel::OK);
  36. }
  37. elseif (!$extension_info[$extension]->status) {
  38. unset($extensions[$extension]);
  39. drush_log(dt('!extension is already uninstalled.', array('!extension' => $extension)), LogLevel::OK);
  40. }
  41. elseif (drush_extension_get_type($extension_info[$extension]) == 'module') {
  42. $dependents = array();
  43. foreach (drush_module_dependents(array($extension), $extension_info) as $dependent) {
  44. if (!in_array($dependent, $required) && ($extension_info[$dependent]->status)) {
  45. $dependents[] = $dependent;
  46. }
  47. }
  48. if (count($dependents)) {
  49. drush_log(dt('To uninstall !extension, the following extensions must be uninstalled first: !required', array('!extension' => $extension, '!required' => implode(', ', $dependents))), LogLevel::ERROR);
  50. unset($extensions[$extension]);
  51. }
  52. }
  53. }
  54. // Discard default theme.
  55. $default_theme = drush_theme_get_default();
  56. if (in_array($default_theme, $extensions)) {
  57. unset($extensions[$default_theme]);
  58. drush_log(dt('!theme is the default theme and can\'t be uninstalled.', array('!theme' => $default_theme)), LogLevel::OK);
  59. }
  60. // Inform the user which extensions will finally be disabled.
  61. if (empty($extensions)) {
  62. return drush_log(dt('There were no extensions that could be uninstalled.'), LogLevel::OK);
  63. }
  64. else {
  65. drush_print(dt('The following extensions will be uninstalled: !extensions', array('!extensions' => implode(', ', $extensions))));
  66. if(!drush_confirm(dt('Do you really want to continue?'))) {
  67. return drush_user_abort();
  68. }
  69. }
  70. // Classify extensions in themes and modules.
  71. $modules = array();
  72. $themes = array();
  73. drush_pm_classify_extensions($extensions, $modules, $themes, $extension_info);
  74. drush_module_uninstall($modules);
  75. drush_theme_uninstall($themes);
  76. // Inform the user of final status.
  77. foreach ($extensions as $extension) {
  78. drush_log(dt('!extension was successfully uninstalled.', array('!extension' => $extension)), LogLevel::OK);
  79. }
  80. }