environment_7.inc

  1. 8.0.x commands/core/drupal/environment_7.inc
  2. 6.x commands/core/drupal/environment_7.inc
  3. 7.x commands/core/drupal/environment_7.inc
  4. 3.x commands/core/drupal/environment_7.inc
  5. master commands/core/drupal/environment_7.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_named_extensions_list Return a list of extensions from a list of named extensions. Both enabled and disabled/uninstalled extensions 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_7.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 (isset($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. * Returns a list of enabled modules.
  99. *
  100. * This is a simplified version of module_list().
  101. */
  102. function drush_module_list() {
  103. $enabled = array();
  104. $rsc = drush_db_select('system', 'name', 'type=:type AND status=:status', array(':type' => 'module', ':status' => 1));
  105. while ($row = drush_db_result($rsc)) {
  106. $enabled[$row] = $row;
  107. }
  108. return $enabled;
  109. }
  110. /**
  111. * Return a list of extensions from a list of named extensions.
  112. * Both enabled and disabled/uninstalled extensions are returned.
  113. */
  114. function drush_get_named_extensions_list($extensions) {
  115. $result = array();
  116. $rsc = drush_db_select('system', array('name', 'status'), 'name IN (:extensions)', array(':extensions' => $extensions));
  117. while ($row = drush_db_fetch_object($rsc)) {
  118. $result[$row->name] = $row;
  119. }
  120. return $result;
  121. }
  122. /**
  123. * Enable a list of modules. It is assumed the list contains all the dependencies not already enabled.
  124. *
  125. * @param $modules
  126. * Array of module names
  127. */
  128. function drush_module_enable($modules) {
  129. // The list of modules already have all the dependencies, but they might not
  130. // be in the correct order. Still pass $enable_dependencies = TRUE so that
  131. // Drupal will enable the modules in the correct order.
  132. module_enable($modules);
  133. // Flush all caches.
  134. drupal_flush_all_caches();
  135. }
  136. /**
  137. * Disable a list of modules. It is assumed the list contains all dependents not already disabled.
  138. *
  139. * @param $modules
  140. * Array of module names
  141. */
  142. function drush_module_disable($modules) {
  143. // The list of modules already have all the dependencies, but they might not
  144. // be in the correct order. Still pass $enable_dependencies = TRUE so that
  145. // Drupal will enable the modules in the correct order.
  146. module_disable($modules);
  147. // Flush all caches.
  148. drupal_flush_all_caches();
  149. }
  150. /**
  151. * Uninstall a list of modules.
  152. *
  153. * @param $modules
  154. * Array of module names
  155. */
  156. function drush_module_uninstall($modules) {
  157. require_once DRUSH_DRUPAL_CORE . '/includes/install.inc';
  158. // Break off 8.x functionality when we get another change.
  159. if (drush_drupal_major_version() >= 8) {
  160. module_uninstall($modules);
  161. }
  162. else {
  163. drupal_uninstall_modules($modules);
  164. }
  165. }
  166. /**
  167. * Get complete information for all available themes.
  168. *
  169. * @param $include_hidden
  170. * Boolean to indicate whether hidden themes should be excluded or not.
  171. * @return
  172. * An array containing theme info for all available themes.
  173. */
  174. function drush_get_themes($include_hidden = TRUE) {
  175. $themes = system_rebuild_theme_data();
  176. if (!$include_hidden) {
  177. foreach ($themes as $key => $theme) {
  178. if (isset($theme->info['hidden'])) {
  179. unset($themes[$key]);
  180. }
  181. }
  182. }
  183. return $themes;
  184. }
  185. /**
  186. * Enable a list of themes.
  187. *
  188. * @param $themes
  189. * Array of theme names.
  190. */
  191. function drush_theme_enable($themes) {
  192. theme_enable($themes);
  193. }
  194. /**
  195. * Disable a list of themes.
  196. *
  197. * @param $themes
  198. * Array of theme names.
  199. */
  200. function drush_theme_disable($themes) {
  201. theme_disable($themes);
  202. }
  203. /**
  204. * Helper function to obtain the severity levels based on Drupal version.
  205. *
  206. * This is a copy of watchdog_severity_levels() without t().
  207. *
  208. * Severity levels, as defined in RFC 3164: http://www.ietf.org/rfc/rfc3164.txt.
  209. *
  210. * @return
  211. * Array of watchdog severity levels.
  212. */
  213. function core_watchdog_severity_levels() {
  214. return array(
  215. WATCHDOG_EMERGENCY=> 'emergency',
  216. WATCHDOG_ALERT => 'alert',
  217. WATCHDOG_CRITICAL => 'critical',
  218. WATCHDOG_ERROR => 'error',
  219. WATCHDOG_WARNING => 'warning',
  220. WATCHDOG_NOTICE => 'notice',
  221. WATCHDOG_INFO => 'info',
  222. WATCHDOG_DEBUG => 'debug',
  223. );
  224. }