You are here

protected function InPlaceUpdate::backup in Automatic Updates 8

Backup before an update.

Parameters

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

string $project_root: The project root directory.

Return value

bool Return TRUE if backup succeeds, FALSE otherwise.

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

File

src/Services/InPlaceUpdate.php, line 376

Class

InPlaceUpdate
Class to apply in-place updates.

Namespace

Drupal\automatic_updates\Services

Code

protected function backup(ArchiverInterface $archive, $project_root) {
  $backup = $this->fileSystem
    ->createFilename('automatic_updates-backup', 'temporary://');
  $this->fileSystem
    ->prepareDirectory($backup, FileSystemInterface::CREATE_DIRECTORY);
  $this->backup = $this->fileSystem
    ->realpath($backup) . DIRECTORY_SEPARATOR;
  if (!$this->backup) {
    return FALSE;
  }
  foreach ($archive
    ->listContents() as $file) {

    // Ignore files that aren't in the files directory.
    if (!$this
      ->stripFileDirectoryPath($file)) {
      continue;
    }
    $success = $this
      ->doBackup($file, $project_root);
    if (!$success) {
      return FALSE;
    }
  }
  $archive
    ->extract($this
    ->getTempDirectory(), [
    self::DELETION_MANIFEST,
  ]);
  foreach ($this
    ->getDeletions() as $deletion) {
    $success = $this
      ->doBackup($deletion, $project_root);
    if (!$success) {
      return FALSE;
    }
  }
  return TRUE;
}