update_5.inc

  1. 3.x commands/core/drupal/update_5.inc
  2. 4.x commands/core/drupal/update_5.inc

Update.php for provisioned sites. This file is a derivative of the standard drupal update.php, which has been modified to allow being run from the command line.

Functions

Namesort descending Description
update_main

File

commands/core/drupal/update_5.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Update.php for provisioned sites.
  5. * This file is a derivative of the standard drupal update.php,
  6. * which has been modified to allow being run from the command
  7. * line.
  8. */
  9. ob_start();
  10. include_once("update.php");
  11. ob_end_clean();
  12. function update_main() {
  13. // Updates only run reliably if user ID #1 is logged in. For example, node_delete() requires elevated perms in D5/6.
  14. if (!drush_get_context('DRUSH_USER')) {
  15. drush_set_option('user', 1);
  16. drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_LOGIN);
  17. }
  18. include_once './includes/install.inc';
  19. drupal_load_updates();
  20. update_fix_schema_version();
  21. update_fix_watchdog_115();
  22. update_fix_watchdog();
  23. update_fix_sessions();
  24. $has_updates = FALSE;
  25. $start = array();
  26. foreach (module_list() as $module) {
  27. $updates = drupal_get_schema_versions($module);
  28. if ($updates !== FALSE) {
  29. $pending[$module] = array();
  30. $updates = drupal_map_assoc($updates);
  31. $schema_version = drupal_get_installed_schema_version($module);
  32. $default = $schema_version;
  33. foreach (array_keys($updates) as $update) {
  34. if ($update > $default) {
  35. $start[$module] = $update;
  36. break;
  37. }
  38. }
  39. // Record any pending updates. Used for confirmation prompt.
  40. foreach (array_keys($updates) as $update) {
  41. if ($update > $schema_version) {
  42. if (class_exists('ReflectionFunction')) {
  43. // The description for an update comes from its Doxygen.
  44. $func = new ReflectionFunction($module. '_update_'. $update);
  45. $description = str_replace(array("\n", '*', '/'), '', $func->getDocComment());
  46. }
  47. if (empty($description)) {
  48. $description = dt('description not available');
  49. }
  50. $pending[$module][] = array("$update - ". trim($description));
  51. $has_updates = TRUE;
  52. }
  53. }
  54. }
  55. }
  56. // Print a list of pending updates for this module and get confirmation.
  57. if ($has_updates) {
  58. drush_print(dt('The following updates are pending:'));
  59. drush_print();
  60. foreach ($pending as $module => $updates) {
  61. if (sizeof($updates)) {
  62. array_unshift($updates, array($module . ' module'));
  63. drush_print_table($updates, TRUE);
  64. drush_print();
  65. }
  66. }
  67. if (!drush_confirm(dt('Do you wish to run all pending updates?'))) {
  68. drush_die('Aborting.');
  69. }
  70. $update_results = array();
  71. foreach ($start as $module => $version) {
  72. drupal_set_installed_schema_version($module, $version - 1);
  73. $updates = drupal_get_schema_versions($module);
  74. $max_version = max($updates);
  75. if ($version <= $max_version) {
  76. drush_log(dt('Updating module @module from schema version @start to schema version @max', array('@module' => $module, '@start' => $version - 1, '@max' => $max_version)));
  77. foreach ($updates as $update) {
  78. $finished = FALSE;
  79. if ($update >= $version) {
  80. while (!$finished) {
  81. // do update
  82. $ret = module_invoke($module, 'update_' . $update);
  83. _drush_log_update_sql($ret);
  84. $finished = 1;
  85. if (isset($ret['#finished'])) {
  86. $finished = $ret['#finished'];
  87. unset($ret['#finished']);
  88. }
  89. }
  90. drupal_set_installed_schema_version($module, $update);
  91. }
  92. }
  93. }
  94. else {
  95. drush_log(dt('No database updates for @module module', array('@module' => $module)), 'success');
  96. }
  97. }
  98. }
  99. else {
  100. drush_log(dt("No database updates required"), 'success');
  101. }
  102. }