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