You are here

protected function InPlaceUpdate::processUpdate in Automatic Updates 8

Process update.

Parameters

\Drupal\Core\Archiver\ArchiverInterface $archive: The archive.

string $project_root: The project root directory.

Return value

bool Return TRUE if update succeeds, FALSE otherwise.

1 call to InPlaceUpdate::processUpdate()
InPlaceUpdate::update in src/Services/InPlaceUpdate.php
Update a project to the next release.

File

src/Services/InPlaceUpdate.php, line 314

Class

InPlaceUpdate
Class to apply in-place updates.

Namespace

Drupal\automatic_updates\Services

Code

protected function processUpdate(ArchiverInterface $archive, $project_root) {
  $archive
    ->extract($this
    ->getTempDirectory());
  foreach ($this
    ->getFilesList($this
    ->getTempDirectory()) as $file) {
    $file_real_path = $this
      ->getFileRealPath($file);
    $file_path = substr($file_real_path, strlen($this
      ->getTempDirectory() . self::ARCHIVE_DIRECTORY));
    $project_real_path = $this
      ->getProjectRealPath($file_path, $project_root);
    try {
      $directory = dirname($project_real_path);
      $this->fileSystem
        ->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY);
      $this->fileSystem
        ->copy($file_real_path, $project_real_path, FileSystemInterface::EXISTS_REPLACE);
      $this->logger
        ->info('"@file" was updated.', [
        '@file' => $project_real_path,
      ]);
    } catch (FileException $exception) {
      return FALSE;
    }
  }
  foreach ($this
    ->getDeletions() as $deletion) {
    try {
      $file_deletion = $this
        ->getProjectRealPath($deletion, $project_root);
      $this->fileSystem
        ->delete($file_deletion);
      $this->logger
        ->info('"@file" was deleted.', [
        '@file' => $file_deletion,
      ]);
    } catch (FileException $exception) {
      return FALSE;
    }
  }
  return TRUE;
}