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_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_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. * Returns a list of enabled modules.
  89. *
  90. * This is a simplified version of module_list().
  91. */
  92. function drush_module_list() {
  93. $enabled = array();
  94. $rsc = drush_db_select('system', 'name', 'type=:type AND status=:status', array(':type' => 'module', ':status' => 1));
  95. while ($row = drush_db_result($rsc)) {
  96. $enabled[$row] = $row;
  97. }
  98. return $enabled;
  99. }
  100. /**
  101. * Return a list of extensions from a list of named extensions.
  102. * Both enabled and disabled/uninstalled extensions are returned.
  103. */
  104. function drush_get_named_extensions_list($extensions) {
  105. $result = array();
  106. $rsc = drush_db_select('system', array('name', 'status'), 'name IN (:extensions)', array(':extensions' => $extensions));
  107. while ($row = drush_db_fetch_object($rsc)) {
  108. $result[$row->name] = $row;
  109. }
  110. return $result;
  111. }
  112. /**
  113. * Enable a list of modules. It is assumed the list contains all the dependencies not already enabled.
  114. *
  115. * @param $modules
  116. * Array of module names
  117. */
  118. function drush_module_enable($modules) {
  119. // Try to install modules previous to enabling.
  120. foreach ($modules as $module) {
  121. _drupal_install_module($module);
  122. }
  123. module_enable($modules);
  124. drush_system_modules_form_submit();
  125. }
  126. /**
  127. * Disable a list of modules. It is assumed the list contains all dependents not already disabled.
  128. *
  129. * @param $modules
  130. * Array of module names
  131. */
  132. function drush_module_disable($modules) {
  133. module_disable($modules, FALSE);
  134. drush_system_modules_form_submit();
  135. }
  136. /**
  137. * Uninstall a list of modules.
  138. *
  139. * @param $modules
  140. * Array of module names
  141. */
  142. function drush_module_uninstall($modules) {
  143. require_once DRUSH_DRUPAL_CORE . '/includes/install.inc';
  144. foreach ($modules as $module) {
  145. drupal_uninstall_module($module);
  146. }
  147. }
  148. /**
  149. * Submit the system modules form.
  150. *
  151. * The modules should already be fully enabled/disabled before calling this
  152. * function. Calling this function just makes sure any activities triggered by
  153. * the form submit (such as admin_role) are completed.
  154. */
  155. function drush_system_modules_form_submit() {
  156. $active_modules = array();
  157. foreach (drush_get_modules(FALSE) as $key => $module) {
  158. if ($module->status == 1) {
  159. $active_modules[$key] = $key;
  160. }
  161. }
  162. module_load_include('inc', 'system', 'system.admin');
  163. $form_state = array('values' => array('status' => $active_modules));
  164. drupal_execute('system_modules', $form_state);
  165. }
  166. /**
  167. * Get complete information for all available themes.
  168. *
  169. * We need to set the type for those themes that are not already in the system table.
  170. *
  171. * @param $include_hidden
  172. * Boolean to indicate whether hidden themes should be excluded or not.
  173. * @return
  174. * An array containing theme info for all available themes.
  175. */
  176. function drush_get_themes($include_hidden = TRUE) {
  177. $themes = system_theme_data();
  178. foreach ($themes as $key => $theme) {
  179. if (!isset($theme->type)) {
  180. $theme->type = 'theme';
  181. }
  182. if ((!$include_hidden) && isset($theme->info['hidden']) && ($theme->info['hidden'])) {
  183. unset($themes[$key]);
  184. }
  185. }
  186. return $themes;
  187. }
  188. /**
  189. * Enable a list of themes.
  190. *
  191. * This function is based on system_themes_form_submit().
  192. *
  193. * @see system_themes_form_submit()
  194. * @param $themes
  195. * Array of theme names.
  196. */
  197. function drush_theme_enable($themes) {
  198. drupal_clear_css_cache();
  199. foreach ($themes as $theme) {
  200. system_initialize_theme_blocks($theme);
  201. }
  202. db_query("UPDATE {system} SET status = 1 WHERE type = 'theme' AND name IN (".db_placeholders($themes, 'text').")", $themes);
  203. list_themes(TRUE);
  204. menu_rebuild();
  205. module_invoke('locale', 'system_update', $themes);
  206. }
  207. /**
  208. * Disable a list of themes.
  209. *
  210. * This function is based on system_themes_form_submit().
  211. *
  212. * @see system_themes_form_submit()
  213. * @param $themes
  214. * Array of theme names.
  215. */
  216. function drush_theme_disable($themes) {
  217. drupal_clear_css_cache();
  218. db_query("UPDATE {system} SET status = 0 WHERE type = 'theme' AND name IN (".db_placeholders($themes, 'text').")", $themes);
  219. list_themes(TRUE);
  220. menu_rebuild();
  221. drupal_rebuild_theme_registry();
  222. module_invoke('locale', 'system_update', $themes);
  223. }
  224. /**
  225. * Helper function to obtain the severity levels based on Drupal version.
  226. *
  227. * This is a copy of watchdog_severity_levels() without t().
  228. *
  229. * Severity levels, as defined in RFC 3164: http://www.ietf.org/rfc/rfc3164.txt.
  230. *
  231. * @return
  232. * Array of watchdog severity levels.
  233. */
  234. function core_watchdog_severity_levels() {
  235. return array(
  236. WATCHDOG_EMERG => 'emergency',
  237. WATCHDOG_ALERT => 'alert',
  238. WATCHDOG_CRITICAL => 'critical',
  239. WATCHDOG_ERROR => 'error',
  240. WATCHDOG_WARNING => 'warning',
  241. WATCHDOG_NOTICE => 'notice',
  242. WATCHDOG_INFO => 'info',
  243. WATCHDOG_DEBUG => 'debug',
  244. );
  245. }