function update_main

8.0.x update_6.inc update_main()
8.0.x update.inc update_main()
8.0.x update_7.inc update_main()
6.x update_6.inc update_main()
6.x update.inc update_main()
6.x update_7.inc update_main()
7.x update_6.inc update_main()
7.x update.inc update_main()
7.x update_7.inc update_main()
3.x update_6.inc update_main()
3.x update_5.inc update_main()
3.x update_7.inc update_main()
4.x update_6.inc update_main()
4.x update.inc update_main()
4.x update_5.inc update_main()
5.x update_6.inc update_main()
5.x update.inc update_main()
5.x update_7.inc update_main()
master update.inc update_main()
master update_7.inc update_main()
1 call to update_main()
drush_core_updatedb in commands/core/core.drush.inc
Command handler. Execute update.php code from drush.

File

commands/core/drupal/update_6.inc, line 376
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.

Code

function update_main() {
  update_main_prepare();

  $start = array();
  $has_updates = FALSE;
  $modules = drupal_get_installed_schema_version(NULL, FALSE, TRUE);
  foreach ($modules as $module => $schema_version) {
    $updates = drupal_get_schema_versions($module);
    // Skip incompatible module updates completely, otherwise test schema versions.
    if (!update_check_incompatibility($module) && $updates !== FALSE && $schema_version >= 0) {
      // module_invoke returns NULL for nonexisting hooks, so if no updates
      // are removed, it will == 0.
      $last_removed = module_invoke($module, 'update_last_removed');
      if ($schema_version < $last_removed) {
        drush_set_error('PROVISION_DRUPAL_UPDATE_FAILED', dt($module . ' module can not be updated. Its schema version is ' . $schema_version . '. Updates up to and including ' . $last_removed . ' have been removed in this release. In order to update ' . $module . ' module, you will first <a href="http://drupal.org/upgrade">need to upgrade</a> to the last version in which these updates were available.'));
        continue;
      }

      $updates = drupal_map_assoc($updates);
      foreach (array_keys($updates) as $update) {
        if ($update > $schema_version) {
          $start[$module] = $update;
          break;
        }
      }

      // Record any pending updates. Used for confirmation prompt.
      foreach (array_keys($updates) as $update) {
        if ($update > $schema_version) {
          if (class_exists('ReflectionFunction')) {
            // The description for an update comes from its Doxygen.
            $func = new ReflectionFunction($module . '_update_' . $update);
            $description = str_replace(array("\n", '*', '/'), '', $func->getDocComment());
          }
          if (empty($description)) {
            $description = dt('description not available');
          }

          $pending[$module][] = array("$update - " . trim($description));
          $has_updates = TRUE;
        }
      }

    }
  }


  // Print a list of pending updates for this module and get confirmation.
  if ($has_updates) {
    drush_print(dt('The following updates are pending:'));
    drush_print();
    foreach ($pending as $module => $updates) {
      if (sizeof($updates)) {
        array_unshift($updates, array($module . ' module'));
        drush_print_table($updates, TRUE);
        drush_print();
      }
    }
    if (!drush_confirm(dt('Do you wish to run all pending updates?'))) {
      return drush_user_abort();
    }
    // Proceed with running all pending updates.
    $operations = array();
    foreach ($start as $module => $version) {
      drupal_set_installed_schema_version($module, $version - 1);
      $updates = drupal_get_schema_versions($module);
      $max_version = max($updates);
      if ($version <= $max_version) {
        drush_log(dt('Updating module @module from schema version @start to schema version @max', array('@module' => $module, '@start' => $version - 1, '@max' => $max_version)));
        foreach ($updates as $update) {
          if ($update >= $version) {
            $operations[] = array('_update_do_one', array($module, $update));
          }
        }
      }
      else {
        drush_log(dt('No database updates for module @module', array('@module' => $module)), 'success');
      }
    }
    $batch = array(
      'operations' => $operations,
      'title' => 'Updating',
      'init_message' => 'Starting updates',
      'error_message' => 'An unrecoverable error has occurred. You can find the error message below. It is advised to copy it to the clipboard for reference.',
      'finished' => 'update_finished',
    );
    batch_set($batch);
    $batch = &batch_get();
    $batch['progressive'] = FALSE;
    drush_backend_batch_process('updatedb-batch-process');
  }
  else {
    drush_log(dt("No database updates required"), 'success');
  }
}