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 5 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.

File

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