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