You are here

protected function DatabaseUpdate::executeDatabaseUpdates in Automatic Updates 8

Execute all outstanding database updates.

1 call to DatabaseUpdate::executeDatabaseUpdates()
DatabaseUpdate::execute in src/Command/DatabaseUpdate.php
Executes the current command.

File

src/Command/DatabaseUpdate.php, line 44

Class

DatabaseUpdate
Database update command.

Namespace

Drupal\automatic_updates\Command

Code

protected function executeDatabaseUpdates() {
  require_once DRUPAL_ROOT . '/core/includes/install.inc';
  require_once DRUPAL_ROOT . '/core/includes/update.inc';
  $logger = \Drupal::logger('automatic_updates');
  drupal_load_updates();
  $start = $dependency_map = $operations = [];
  foreach (update_get_update_list() as $module => $update) {
    $start[$module] = $update['start'];
  }
  $updates = update_resolve_dependencies($start);
  foreach ($updates as $function => $update) {
    $dependency_map[$function] = !empty($update['reverse_paths']) ? array_keys($update['reverse_paths']) : [];
  }
  foreach ($updates as $function => $update) {
    if ($update['allowed']) {

      // Set the installed version of each module so updates will start at the
      // correct place. (The updates are already sorted, so we can simply base
      // this on the first one we come across in the above foreach loop.)
      if (isset($start[$update['module']])) {
        drupal_set_installed_schema_version($update['module'], $update['number'] - 1);
        unset($start[$update['module']]);
      }
      $this
        ->executeDatabaseUpdate('update_do_one', [
        $update['module'],
        $update['number'],
        $dependency_map[$function],
      ]);
    }
  }
  $post_updates = \Drupal::service('update.post_update_registry')
    ->getPendingUpdateFunctions();
  if ($post_updates) {

    // Now we rebuild all caches and after that execute hook_post_update().
    $logger
      ->info('Starting cache clear pre-step of database update.');
    automatic_updates_console_command('cache:rebuild');
    $logger
      ->info('Finished cache clear pre-step of database update.');
    foreach ($post_updates as $function) {
      $this
        ->executeDatabaseUpdate('update_invoke_post_update', [
        $function,
      ]);
    }
  }
}