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_system_modules_form_submit Submit the system modules form.
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. * @return
  13. * An array containing module info for all available modules.
  14. */
  15. function drush_get_modules() {
  16. return system_rebuild_module_data();
  17. }
  18. /**
  19. * Returns drupal required modules, including modules declared as required dynamically.
  20. */
  21. function _drush_drupal_required_modules($module_info) {
  22. $required = drupal_required_modules();
  23. foreach ($module_info as $name => $module) {
  24. if (isset($module->info['required']) && $module->info['required']) {
  25. $required[] = $name;
  26. }
  27. }
  28. return array_unique($required);
  29. }
  30. /**
  31. * Return dependencies and its status for modules.
  32. *
  33. * @param $modules
  34. * Array of module names
  35. * @param $module_info
  36. * Drupal 'files' array for modules as returned by drush_get_modules().
  37. * @return
  38. * Array with dependencies and status for $modules
  39. */
  40. function drush_check_module_dependencies($modules, $module_info) {
  41. $status = array();
  42. foreach ($modules as $key => $module) {
  43. $dependencies = array_reverse($module_info[$module]->requires);
  44. $unmet_dependencies = array_diff(array_keys($dependencies), array_keys($module_info));
  45. if (!empty($unmet_dependencies)) {
  46. $status[$key]['error'] = array(
  47. 'code' => 'DRUSH_PM_ENABLE_DEPENDENCY_NOT_FOUND',
  48. '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)))
  49. );
  50. }
  51. else {
  52. // check for version incompatibility
  53. foreach ($dependencies as $dependency_name => $v) {
  54. $current_version = $module_info[$dependency_name]->info['version'];
  55. $current_version = str_replace(DRUPAL_CORE_COMPATIBILITY . '-', '', $current_version);
  56. $incompatibility = drupal_check_incompatibility($v, $current_version);
  57. if (!is_null($incompatibility)) {
  58. $status[$key]['error'] = array(
  59. 'code' => 'DRUSH_PM_ENABLE_DEPENDENCY_VERSION_MISMATCH',
  60. '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))
  61. );
  62. }
  63. }
  64. }
  65. $status[$key]['unmet-dependencies'] = $unmet_dependencies;
  66. $status[$key]['dependencies'] = array_keys($dependencies);
  67. }
  68. return $status;
  69. }
  70. /**
  71. * Return dependents of modules.
  72. *
  73. * @param $modules
  74. * Array of module names
  75. * @param $module_info
  76. * Drupal 'files' array for modules as returned by drush_get_modules().
  77. * @return
  78. * Array with dependents for each one of $modules
  79. */
  80. function drush_module_dependents($modules, $module_info) {
  81. $dependents = array();
  82. foreach ($modules as $module) {
  83. $dependents = array_merge($dependents, drupal_map_assoc(array_keys($module_info[$module]->required_by)));
  84. }
  85. return array_unique($dependents);
  86. }
  87. /**
  88. * Enable a list of modules. It is assumed the list contains all the dependencies not already enabled.
  89. *
  90. * @param $modules
  91. * Array of module names
  92. */
  93. function drush_module_enable($modules) {
  94. // The list of modules already have all the dependencies, but they might not
  95. // be in the correct order. Still pass $enable_dependencies = TRUE so that
  96. // Drupal will enable the modules in the correct order.
  97. module_enable($modules);
  98. }
  99. /**
  100. * Disable a list of modules. It is assumed the list contains all dependents not already disabled.
  101. *
  102. * @param $modules
  103. * Array of module names
  104. */
  105. function drush_module_disable($modules) {
  106. // The list of modules already have all the dependencies, but they might not
  107. // be in the correct order. Still pass $enable_dependencies = TRUE so that
  108. // Drupal will enable the modules in the correct order.
  109. module_disable($modules);
  110. }
  111. /**
  112. * Uninstall a list of modules.
  113. *
  114. * @param $modules
  115. * Array of module names
  116. */
  117. function drush_module_uninstall($modules) {
  118. require_once drush_get_context('DRUSH_DRUPAL_ROOT') . '/includes/install.inc';
  119. drupal_uninstall_modules($modules);
  120. }
  121. /**
  122. * Submit the system modules form.
  123. *
  124. * The modules should already be fully enabled/disabled before calling this
  125. * function. Calling this function just makes sure any activities triggered by
  126. * the form submit (such as admin_role) are completed.
  127. */
  128. function drush_system_modules_form_submit($active_modules) {
  129. module_load_include('inc', 'system', 'system.admin');
  130. $form_state = array('values' => array('status' => $active_modules));
  131. drupal_form_submit('system_modules', $form_state);
  132. // Because normally system_modules_submit would call this function if modules
  133. // had been changed, in this case we are submitting the module form without
  134. // any changes, so we need to clear caches manually.
  135. drupal_flush_all_caches();
  136. }
  137. /**
  138. * Get complete information for all available themes.
  139. *
  140. * @return
  141. * An array containing theme info for all available themes.
  142. */
  143. function drush_get_themes() {
  144. return system_rebuild_theme_data();
  145. }
  146. /**
  147. * Enable a list of themes.
  148. *
  149. * @param $themes
  150. * Array of theme names.
  151. */
  152. function drush_theme_enable($themes) {
  153. theme_enable($themes);
  154. }
  155. /**
  156. * Disable a list of themes.
  157. *
  158. * @param $themes
  159. * Array of theme names.
  160. */
  161. function drush_theme_disable($themes) {
  162. theme_disable($themes);
  163. }
  164. /**
  165. * Helper function to obtain the severity levels based on Drupal version.
  166. *
  167. * This is a copy of watchdog_severity_levels() without t().
  168. *
  169. * Severity levels, as defined in RFC 3164: http://www.ietf.org/rfc/rfc3164.txt.
  170. *
  171. * @return
  172. * Array of watchdog severity levels.
  173. */
  174. function core_watchdog_severity_levels() {
  175. return array(
  176. WATCHDOG_EMERGENCY=> 'emergency',
  177. WATCHDOG_ALERT => 'alert',
  178. WATCHDOG_CRITICAL => 'critical',
  179. WATCHDOG_ERROR => 'error',
  180. WATCHDOG_WARNING => 'warning',
  181. WATCHDOG_NOTICE => 'notice',
  182. WATCHDOG_INFO => 'info',
  183. WATCHDOG_DEBUG => 'debug',
  184. );
  185. }