You are here

public function TestController::update in Automatic Updates 8.2

Performs an in-place update to a given version of Drupal core.

This executes the update immediately, in one request, without using the batch system or cron as wrappers.

Parameters

string $to_version: The version of core to update to.

Return value

\Symfony\Component\HttpFoundation\Response The response object.

1 string reference to 'TestController::update'
automatic_updates_test.routing.yml in tests/modules/automatic_updates_test/automatic_updates_test.routing.yml
tests/modules/automatic_updates_test/automatic_updates_test.routing.yml

File

tests/modules/automatic_updates_test/src/TestController.php, line 27

Class

TestController

Namespace

Drupal\automatic_updates_test

Code

public function update(string $to_version) : Response {

  // Let it take as long as it needs.
  Environment::setTimeLimit(0);

  /** @var \Drupal\automatic_updates\Updater $updater */
  $updater = \Drupal::service('automatic_updates.updater');
  try {
    $updater
      ->begin([
      'drupal' => $to_version,
    ]);
    $updater
      ->stage();
    $updater
      ->commit();
    $updater
      ->clean();
    $project = (new UpdateRecommender())
      ->getProjectInfo();
    $content = $project['existing_version'];
    $status = 200;
  } catch (UpdateException $e) {
    $messages = [];
    foreach ($e
      ->getValidationResults() as $result) {
      if ($summary = $result
        ->getSummary()) {
        $messages[] = $summary;
      }
      $messages = array_merge($messages, $result
        ->getMessages());
    }
    $content = implode('<br />', $messages);
    $status = 500;
  }
  return new HtmlResponse($content, $status);
}