You are here

protected static function InPlaceUpdate::backup in Automatic Updates 7

Backup before an update.

Parameters

\ArchiverZip $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 ./InPlaceUpdate.php

File

./InPlaceUpdate.php, line 268

Class

InPlaceUpdate
Class to apply in-place updates.

Code

protected static function backup(\ArchiverZip $archive, $project_root) {
  $backup = file_create_filename('automatic_updates-backup', 'temporary://');
  file_prepare_directory($backup, FILE_CREATE_DIRECTORY);
  self::$backup = drupal_realpath($backup) . DIRECTORY_SEPARATOR;
  if (!self::$backup) {
    return FALSE;
  }
  foreach ($archive
    ->listContents() as $file) {

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