You are here

public function InPlaceUpdate::update in Automatic Updates 8

Update a project to the next release.

Parameters

\Drupal\automatic_updates\UpdateMetadata $metadata: The update metadata.

Return value

bool TRUE if project was successfully updated, FALSE otherwise.

Overrides UpdateInterface::update

File

src/Services/InPlaceUpdate.php, line 134

Class

InPlaceUpdate
Class to apply in-place updates.

Namespace

Drupal\automatic_updates\Services

Code

public function update(UpdateMetadata $metadata) {

  // Bail immediately on updates if error category checks fail.

  /** @var \Drupal\automatic_updates\ReadinessChecker\ReadinessCheckerManagerInterface $readiness_check_manager */
  $checker = \Drupal::service('automatic_updates.readiness_checker');
  if ($checker
    ->run(ReadinessCheckerManagerInterface::ERROR)) {
    return FALSE;
  }
  $success = FALSE;
  if ($metadata
    ->getProjectName() === 'drupal') {
    $project_root = $this->rootPath;
  }
  else {
    $project_root = drupal_get_path($metadata
      ->getProjectType(), $metadata
      ->getProjectName());
  }
  if ($archive = $this
    ->getArchive($metadata)) {
    $modified = $this
      ->checkModifiedFiles($metadata, $archive);
    if (!$modified && $this
      ->backup($archive, $project_root)) {
      $this->logger
        ->info('In place update has started.');
      try {
        $success = $this
          ->processUpdate($archive, $project_root);
        $this->logger
          ->info('In place update has finished.');
      } catch (\Throwable $throwable) {
        $this->logger
          ->info('In place update failed.');
        watchdog_exception($throwable);
      } catch (\Exception $exception) {
        $this->logger
          ->info('In place update failed.');
        watchdog_exception($exception);
      }
      if ($success) {
        $process = automatic_updates_console_command('updatedb:status');
        if ($success && $process
          ->getOutput()) {
          $this->logger
            ->info('Database update handling has started.');
          $success = $this
            ->handleDatabaseUpdates();
          $this->logger
            ->info('Database update handling has finished.');
        }
      }
      if (!$success) {
        $this->logger
          ->info('Rollback has started.');
        $this
          ->rollback($project_root);
        $this->logger
          ->info('Rollback has finished.');
      }
      if ($success) {
        $this->logger
          ->info('Cache clear has started.');
        $this
          ->cacheRebuild();
        $this->logger
          ->info('Cache clear has finished.');
      }
    }
  }

  /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher */
  $event_dispatcher = \Drupal::service('event_dispatcher');
  $event = new PostUpdateEvent($metadata, $success);
  $event_dispatcher
    ->dispatch(UpdateEvents::POST_UPDATE, $event);
  return $success;
}