environment_5.inc

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