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 8 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_named_extensions_list Return a list of modules from a list of named modules. Both enabled and disabled/uninstalled modules are returned.
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_list Returns a list of enabled modules.
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 8 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. foreach ($modules as $key => $module) {
  20. $module->type = 'module';
  21. if ((!$include_hidden) && (isset($module->info['hidden']))) {
  22. unset($modules[$key]);
  23. }
  24. else {
  25. $module->schema_version = drupal_get_installed_schema_version($key);
  26. }
  27. }
  28. return $modules;
  29. }
  30. /**
  31. * Returns drupal required modules, including modules declared as required dynamically.
  32. */
  33. function _drush_drupal_required_modules($module_info) {
  34. $required = drupal_required_modules();
  35. foreach ($module_info as $name => $module) {
  36. if (isset($module->info['required']) && $module->info['required']) {
  37. $required[] = $name;
  38. }
  39. }
  40. return array_unique($required);
  41. }
  42. /**
  43. * Return dependencies and its status for modules.
  44. *
  45. * @param $modules
  46. * Array of module names
  47. * @param $module_info
  48. * Drupal 'files' array for modules as returned by drush_get_modules().
  49. * @return
  50. * Array with dependencies and status for $modules
  51. */
  52. function drush_check_module_dependencies($modules, $module_info) {
  53. $status = array();
  54. foreach ($modules as $key => $module) {
  55. $dependencies = array_reverse($module_info[$module]->requires);
  56. $unmet_dependencies = array_diff(array_keys($dependencies), array_keys($module_info));
  57. if (!empty($unmet_dependencies)) {
  58. $status[$key]['error'] = array(
  59. 'code' => 'DRUSH_PM_ENABLE_DEPENDENCY_NOT_FOUND',
  60. '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)))
  61. );
  62. }
  63. else {
  64. // check for version incompatibility
  65. foreach ($dependencies as $dependency_name => $v) {
  66. $current_version = $module_info[$dependency_name]->info['version'];
  67. $current_version = str_replace(DRUPAL_CORE_COMPATIBILITY . '-', '', $current_version);
  68. $incompatibility = drupal_check_incompatibility($v, $current_version);
  69. if (isset($incompatibility)) {
  70. $status[$key]['error'] = array(
  71. 'code' => 'DRUSH_PM_ENABLE_DEPENDENCY_VERSION_MISMATCH',
  72. '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))
  73. );
  74. }
  75. }
  76. }
  77. $status[$key]['unmet-dependencies'] = $unmet_dependencies;
  78. $status[$key]['dependencies'] = array_keys($dependencies);
  79. }
  80. return $status;
  81. }
  82. /**
  83. * Return dependents of modules.
  84. *
  85. * @param $modules
  86. * Array of module names
  87. * @param $module_info
  88. * Drupal 'files' array for modules as returned by drush_get_modules().
  89. * @return
  90. * Array with dependents for each one of $modules
  91. */
  92. function drush_module_dependents($modules, $module_info) {
  93. $dependents = array();
  94. foreach ($modules as $module) {
  95. $dependents = array_merge($dependents, drupal_map_assoc(array_keys($module_info[$module]->required_by)));
  96. }
  97. return array_unique($dependents);
  98. }
  99. /**
  100. * Returns a list of enabled modules.
  101. *
  102. * This is a wrapper for module_list().
  103. */
  104. function drush_module_list() {
  105. return module_list('module_enabled');
  106. }
  107. /**
  108. * Return a list of modules from a list of named modules.
  109. * Both enabled and disabled/uninstalled modules are returned.
  110. */
  111. function drush_get_named_extensions_list($extensions) {
  112. $result = array();
  113. $modules = drush_get_modules();
  114. foreach($modules as $name => $module) {
  115. if (in_array($name, $extensions)) {
  116. $result[$name] = $module;
  117. }
  118. }
  119. $themes = drush_get_themes();
  120. foreach($themes as $name => $theme) {
  121. if (in_array($name, $extensions)) {
  122. $result[$name] = $theme;
  123. }
  124. }
  125. return $result;
  126. }
  127. /**
  128. * Enable a list of modules. It is assumed the list contains all the dependencies not already enabled.
  129. *
  130. * @param $modules
  131. * Array of module names
  132. */
  133. function drush_module_enable($modules) {
  134. // The list of modules already have all the dependencies, but they might not
  135. // be in the correct order. Still pass $enable_dependencies = TRUE so that
  136. // Drupal will enable the modules in the correct order.
  137. module_enable($modules);
  138. // Flush all caches.
  139. drupal_flush_all_caches();
  140. }
  141. /**
  142. * Disable a list of modules. It is assumed the list contains all dependents not already disabled.
  143. *
  144. * @param $modules
  145. * Array of module names
  146. */
  147. function drush_module_disable($modules) {
  148. // The list of modules already have all the dependencies, but they might not
  149. // be in the correct order. Still pass $enable_dependencies = TRUE so that
  150. // Drupal will enable the modules in the correct order.
  151. module_disable($modules);
  152. // Flush all caches.
  153. drupal_flush_all_caches();
  154. }
  155. /**
  156. * Uninstall a list of modules.
  157. *
  158. * @param $modules
  159. * Array of module names
  160. */
  161. function drush_module_uninstall($modules) {
  162. require_once DRUSH_DRUPAL_CORE . '/includes/install.inc';
  163. // Break off 8.x functionality when we get another change.
  164. if (drush_drupal_major_version() >= 8) {
  165. module_uninstall($modules);
  166. }
  167. else {
  168. drupal_uninstall_modules($modules);
  169. }
  170. }
  171. /**
  172. * Get complete information for all available themes.
  173. *
  174. * @param $include_hidden
  175. * Boolean to indicate whether hidden themes should be excluded or not.
  176. * @return
  177. * An array containing theme info for all available themes.
  178. */
  179. function drush_get_themes($include_hidden = TRUE) {
  180. $themes = system_rebuild_theme_data();
  181. foreach ($themes as $key => $theme) {
  182. $theme->type = 'theme';
  183. if (!$include_hidden) {
  184. if (isset($theme->info['hidden'])) {
  185. unset($themes[$key]);
  186. }
  187. }
  188. }
  189. return $themes;
  190. }
  191. /**
  192. * Enable a list of themes.
  193. *
  194. * @param $themes
  195. * Array of theme names.
  196. */
  197. function drush_theme_enable($themes) {
  198. theme_enable($themes);
  199. }
  200. /**
  201. * Disable a list of themes.
  202. *
  203. * @param $themes
  204. * Array of theme names.
  205. */
  206. function drush_theme_disable($themes) {
  207. theme_disable($themes);
  208. }
  209. /**
  210. * Helper function to obtain the severity levels based on Drupal version.
  211. *
  212. * This is a copy of watchdog_severity_levels() without t().
  213. *
  214. * Severity levels, as defined in RFC 3164: http://www.ietf.org/rfc/rfc3164.txt.
  215. *
  216. * @return
  217. * Array of watchdog severity levels.
  218. */
  219. function core_watchdog_severity_levels() {
  220. return array(
  221. WATCHDOG_EMERGENCY=> 'emergency',
  222. WATCHDOG_ALERT => 'alert',
  223. WATCHDOG_CRITICAL => 'critical',
  224. WATCHDOG_ERROR => 'error',
  225. WATCHDOG_WARNING => 'warning',
  226. WATCHDOG_NOTICE => 'notice',
  227. WATCHDOG_INFO => 'info',
  228. WATCHDOG_DEBUG => 'debug',
  229. );
  230. }