environment.inc

  1. 8.0.x includes/environment.inc
  2. 8.0.x commands/core/drupal/environment.inc
  3. 6.x includes/environment.inc
  4. 6.x commands/core/drupal/environment.inc
  5. 7.x includes/environment.inc
  6. 7.x commands/core/drupal/environment.inc
  7. 3.x includes/environment.inc
  8. 4.x commands/core/drupal/environment.inc
  9. 4.x includes/environment.inc
  10. 5.x commands/core/drupal/environment.inc
  11. 5.x includes/environment.inc
  12. master commands/core/drupal/environment.inc
  13. master includes/environment.inc

Specific functions for a drupal 7 environment. drush_include_engine() magically includes either this file or environment_X.inc depending on which version of drupal drush is called from.

Functions

Namesort descending Description
core_watchdog_severity_levels Helper function to obtain the severity levels based on Drupal version.
drush_check_module_dependencies Return dependencies and its status for modules.
drush_get_modules Get complete information for all available modules.
drush_get_themes Get complete information for all available themes.
drush_module_dependents Return dependents of modules.
drush_module_disable Disable a list of modules. It is assumed the list contains all dependents not already disabled.
drush_module_enable Enable a list of modules. It is assumed the list contains all the dependencies not already enabled.
drush_module_uninstall Uninstall a list of modules.
drush_theme_disable Disable a list of themes.
drush_theme_enable Enable a list of themes.
_drush_drupal_required_modules Returns drupal required modules, including modules declared as required dynamically.

File

commands/core/drupal/environment.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Specific functions for a drupal 7 environment.
  5. * drush_include_engine() magically includes either this file
  6. * or environment_X.inc depending on which version of drupal drush
  7. * is called from.
  8. */
  9. /**
  10. * Get complete information for all available modules.
  11. *
  12. * @param $include_hidden
  13. * Boolean to indicate whether hidden modules should be excluded or not.
  14. * @return
  15. * An array containing module info for all available modules.
  16. */
  17. function drush_get_modules($include_hidden = TRUE) {
  18. $modules = system_rebuild_module_data();
  19. if (!$include_hidden) {
  20. foreach ($modules as $key => $module) {
  21. if (isset($module->info['hidden'])) {
  22. unset($modules[$key]);
  23. }
  24. }
  25. }
  26. return $modules;
  27. }
  28. /**
  29. * Returns drupal required modules, including modules declared as required dynamically.
  30. */
  31. function _drush_drupal_required_modules($module_info) {
  32. $required = drupal_required_modules();
  33. foreach ($module_info as $name => $module) {
  34. if (isset($module->info['required']) && $module->info['required']) {
  35. $required[] = $name;
  36. }
  37. }
  38. return array_unique($required);
  39. }
  40. /**
  41. * Return dependencies and its status for modules.
  42. *
  43. * @param $modules
  44. * Array of module names
  45. * @param $module_info
  46. * Drupal 'files' array for modules as returned by drush_get_modules().
  47. * @return
  48. * Array with dependencies and status for $modules
  49. */
  50. function drush_check_module_dependencies($modules, $module_info) {
  51. $status = array();
  52. foreach ($modules as $key => $module) {
  53. $dependencies = array_reverse($module_info[$module]->requires);
  54. $unmet_dependencies = array_diff(array_keys($dependencies), array_keys($module_info));
  55. if (!empty($unmet_dependencies)) {
  56. $status[$key]['error'] = array(
  57. 'code' => 'DRUSH_PM_ENABLE_DEPENDENCY_NOT_FOUND',
  58. 'message' => dt('Module !module cannot be enabled because it depends on the following modules which could not be found: !unmet_dependencies', array('!module' => $module, '!unmet_dependencies' => implode(',', $unmet_dependencies)))
  59. );
  60. }
  61. else {
  62. // check for version incompatibility
  63. foreach ($dependencies as $dependency_name => $v) {
  64. $current_version = $module_info[$dependency_name]->info['version'];
  65. $current_version = str_replace(DRUPAL_CORE_COMPATIBILITY . '-', '', $current_version);
  66. $incompatibility = drupal_check_incompatibility($v, $current_version);
  67. if (!is_null($incompatibility)) {
  68. $status[$key]['error'] = array(
  69. 'code' => 'DRUSH_PM_ENABLE_DEPENDENCY_VERSION_MISMATCH',
  70. 'message' => dt('Module !module cannot be enabled because it depends on !dependency !required_version but !current_version is available', array('!module' => $module, '!dependency' => $dependency_name, '!required_version' => $incompatibility, '!current_version' => $current_version))
  71. );
  72. }
  73. }
  74. }
  75. $status[$key]['unmet-dependencies'] = $unmet_dependencies;
  76. $status[$key]['dependencies'] = array_keys($dependencies);
  77. }
  78. return $status;
  79. }
  80. /**
  81. * Return dependents of modules.
  82. *
  83. * @param $modules
  84. * Array of module names
  85. * @param $module_info
  86. * Drupal 'files' array for modules as returned by drush_get_modules().
  87. * @return
  88. * Array with dependents for each one of $modules
  89. */
  90. function drush_module_dependents($modules, $module_info) {
  91. $dependents = array();
  92. foreach ($modules as $module) {
  93. $dependents = array_merge($dependents, drupal_map_assoc(array_keys($module_info[$module]->required_by)));
  94. }
  95. return array_unique($dependents);
  96. }
  97. /**
  98. * Enable a list of modules. It is assumed the list contains all the dependencies not already enabled.
  99. *
  100. * @param $modules
  101. * Array of module names
  102. */
  103. function drush_module_enable($modules) {
  104. // The list of modules already have all the dependencies, but they might not
  105. // be in the correct order. Still pass $enable_dependencies = TRUE so that
  106. // Drupal will enable the modules in the correct order.
  107. module_enable($modules);
  108. // Flush all caches.
  109. drupal_flush_all_caches();
  110. }
  111. /**
  112. * Disable a list of modules. It is assumed the list contains all dependents not already disabled.
  113. *
  114. * @param $modules
  115. * Array of module names
  116. */
  117. function drush_module_disable($modules) {
  118. // The list of modules already have all the dependencies, but they might not
  119. // be in the correct order. Still pass $enable_dependencies = TRUE so that
  120. // Drupal will enable the modules in the correct order.
  121. module_disable($modules);
  122. // Flush all caches.
  123. drupal_flush_all_caches();
  124. }
  125. /**
  126. * Uninstall a list of modules.
  127. *
  128. * @param $modules
  129. * Array of module names
  130. */
  131. function drush_module_uninstall($modules) {
  132. require_once DRUSH_DRUPAL_CORE . '/includes/install.inc';
  133. drupal_uninstall_modules($modules);
  134. }
  135. /**
  136. * Get complete information for all available themes.
  137. *
  138. * @param $include_hidden
  139. * Boolean to indicate whether hidden themes should be excluded or not.
  140. * @return
  141. * An array containing theme info for all available themes.
  142. */
  143. function drush_get_themes($include_hidden = TRUE) {
  144. $themes = system_rebuild_theme_data();
  145. if (!$include_hidden) {
  146. foreach ($themes as $key => $theme) {
  147. if (isset($theme->info['hidden'])) {
  148. unset($themes[$key]);
  149. }
  150. }
  151. }
  152. return $themes;
  153. }
  154. /**
  155. * Enable a list of themes.
  156. *
  157. * @param $themes
  158. * Array of theme names.
  159. */
  160. function drush_theme_enable($themes) {
  161. theme_enable($themes);
  162. }
  163. /**
  164. * Disable a list of themes.
  165. *
  166. * @param $themes
  167. * Array of theme names.
  168. */
  169. function drush_theme_disable($themes) {
  170. theme_disable($themes);
  171. }
  172. /**
  173. * Helper function to obtain the severity levels based on Drupal version.
  174. *
  175. * This is a copy of watchdog_severity_levels() without t().
  176. *
  177. * Severity levels, as defined in RFC 3164: http://www.ietf.org/rfc/rfc3164.txt.
  178. *
  179. * @return
  180. * Array of watchdog severity levels.
  181. */
  182. function core_watchdog_severity_levels() {
  183. return array(
  184. WATCHDOG_EMERGENCY=> 'emergency',
  185. WATCHDOG_ALERT => 'alert',
  186. WATCHDOG_CRITICAL => 'critical',
  187. WATCHDOG_ERROR => 'error',
  188. WATCHDOG_WARNING => 'warning',
  189. WATCHDOG_NOTICE => 'notice',
  190. WATCHDOG_INFO => 'info',
  191. WATCHDOG_DEBUG => 'debug',
  192. );
  193. }