environment_6.inc

  1. 8.0.x commands/core/drupal/environment_6.inc
  2. 6.x commands/core/drupal/environment_6.inc
  3. 7.x commands/core/drupal/environment_6.inc
  4. 3.x commands/core/drupal/environment_6.inc
  5. 4.x commands/core/drupal/environment_6.inc
  6. 5.x commands/core/drupal/environment_6.inc

Specific functions for a drupal 6 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 their dependencies.

File

commands/core/drupal/environment_6.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Specific functions for a drupal 6 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. * We need to set the type for those modules that are not already in the system table.
  13. *
  14. * @return
  15. * An array containing module info for all available modules.
  16. */
  17. function drush_get_modules() {
  18. $modules = module_rebuild_cache();
  19. foreach ($modules as $module) {
  20. if (!isset($module->type)) {
  21. $module->type = 'module';
  22. }
  23. }
  24. return $modules;
  25. }
  26. /**
  27. * Returns drupal required modules, including their dependencies.
  28. *
  29. * A module may alter other module's .info to set a dependency on it.
  30. * See for example http://drupal.org/project/phpass
  31. */
  32. function _drush_drupal_required_modules($module_info) {
  33. $required = drupal_required_modules();
  34. foreach ($required as $module) {
  35. $required = array_merge($required, $module_info[$module]->info['dependencies']);
  36. }
  37. return $required;
  38. }
  39. /**
  40. * Return dependencies and its status for modules.
  41. *
  42. * @param $modules
  43. * Array of module names
  44. * @param $module_info
  45. * Drupal 'files' array for modules as returned by drush_get_modules().
  46. * @return
  47. * Array with dependencies and status for $modules
  48. */
  49. function drush_check_module_dependencies($modules, $module_info) {
  50. $status = array();
  51. foreach ($modules as $key => $module) {
  52. $dependencies = array_reverse($module_info[$module]->info['dependencies']);
  53. $unmet_dependencies = array_diff($dependencies, array_keys($module_info));
  54. if (!empty($unmet_dependencies)) {
  55. $status[$key]['error'] = array(
  56. 'code' => 'DRUSH_PM_ENABLE_DEPENDENCY_NOT_FOUND',
  57. '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)))
  58. );
  59. }
  60. $status[$key]['unmet-dependencies'] = $unmet_dependencies;
  61. $status[$key]['dependencies'] = $dependencies;
  62. }
  63. return $status;
  64. }
  65. /**
  66. * Return dependents of modules.
  67. *
  68. * @param $modules
  69. * Array of module names
  70. * @param $module_info
  71. * Drupal 'files' array for modules as returned by drush_get_modules().
  72. * @return
  73. * Array with dependents for each one of $modules
  74. */
  75. function drush_module_dependents($modules, $module_info) {
  76. $dependents = array();
  77. foreach ($modules as $module) {
  78. $dependents = array_merge($dependents, $module_info[$module]->info['dependents']);
  79. }
  80. return array_unique($dependents);
  81. }
  82. /**
  83. * Enable a list of modules. It is assumed the list contains all the dependencies not already enabled.
  84. *
  85. * @param $modules
  86. * Array of module names
  87. */
  88. function drush_module_enable($modules) {
  89. // Try to install modules previous to enabling.
  90. foreach ($modules as $module) {
  91. _drupal_install_module($module);
  92. }
  93. module_enable($modules);
  94. }
  95. /**
  96. * Disable a list of modules. It is assumed the list contains all dependents not already disabled.
  97. *
  98. * @param $modules
  99. * Array of module names
  100. */
  101. function drush_module_disable($modules) {
  102. module_disable($modules, FALSE);
  103. }
  104. /**
  105. * Uninstall a list of modules.
  106. *
  107. * @param $modules
  108. * Array of module names
  109. */
  110. function drush_module_uninstall($modules) {
  111. require_once drush_get_context('DRUSH_DRUPAL_ROOT') . '/includes/install.inc';
  112. foreach ($modules as $module) {
  113. drupal_uninstall_module($module);
  114. }
  115. }
  116. /**
  117. * Submit the system modules form.
  118. *
  119. * The modules should already be fully enabled/disabled before calling this
  120. * function. Calling this function just makes sure any activities triggered by
  121. * the form submit (such as admin_role) are completed.
  122. */
  123. function drush_system_modules_form_submit($active_modules) {
  124. module_load_include('inc', 'system', 'system.admin');
  125. $form_state = array('values' => array('status' => $active_modules));
  126. drupal_execute('system_modules', $form_state);
  127. }
  128. /**
  129. * Get complete information for all available themes.
  130. *
  131. * We need to set the type for those themes that are not already in the system table.
  132. *
  133. * @return
  134. * An array containing theme info for all available themes.
  135. */
  136. function drush_get_themes() {
  137. $themes = system_theme_data();
  138. foreach ($themes as $theme) {
  139. if (!isset($theme->type)) {
  140. $theme->type = 'theme';
  141. }
  142. }
  143. return $themes;
  144. }
  145. /**
  146. * Enable a list of themes.
  147. *
  148. * This function is based on system_themes_form_submit().
  149. *
  150. * @see system_themes_form_submit()
  151. * @param $themes
  152. * Array of theme names.
  153. */
  154. function drush_theme_enable($themes) {
  155. drupal_clear_css_cache();
  156. foreach ($themes as $theme) {
  157. system_initialize_theme_blocks($theme);
  158. }
  159. db_query("UPDATE {system} SET status = 1 WHERE type = 'theme' AND name IN (".db_placeholders($themes, 'text').")", $themes);
  160. list_themes(TRUE);
  161. menu_rebuild();
  162. module_invoke('locale', 'system_update', $themes);
  163. }
  164. /**
  165. * Disable a list of themes.
  166. *
  167. * This function is based on system_themes_form_submit().
  168. *
  169. * @see system_themes_form_submit()
  170. * @param $themes
  171. * Array of theme names.
  172. */
  173. function drush_theme_disable($themes) {
  174. drupal_clear_css_cache();
  175. db_query("UPDATE {system} SET status = 0 WHERE type = 'theme' AND name IN (".db_placeholders($themes, 'text').")", $themes);
  176. list_themes(TRUE);
  177. menu_rebuild();
  178. drupal_rebuild_theme_registry();
  179. module_invoke('locale', 'system_update', $themes);
  180. }
  181. /**
  182. * Helper function to obtain the severity levels based on Drupal version.
  183. *
  184. * This is a copy of watchdog_severity_levels() without t().
  185. *
  186. * Severity levels, as defined in RFC 3164: http://www.ietf.org/rfc/rfc3164.txt.
  187. *
  188. * @return
  189. * Array of watchdog severity levels.
  190. */
  191. function core_watchdog_severity_levels() {
  192. return array(
  193. WATCHDOG_EMERG => 'emergency',
  194. WATCHDOG_ALERT => 'alert',
  195. WATCHDOG_CRITICAL => 'critical',
  196. WATCHDOG_ERROR => 'error',
  197. WATCHDOG_WARNING => 'warning',
  198. WATCHDOG_NOTICE => 'notice',
  199. WATCHDOG_INFO => 'info',
  200. WATCHDOG_DEBUG => 'debug',
  201. );
  202. }