You are here

function backup_migrate_files_destination_archivesource::_restore_from_file_php in Backup and Migrate 6.3

Same name and namespace in other branches
  1. 8.3 includes/sources.archivesource.inc \backup_migrate_files_destination_archivesource::_restore_from_file_php()
  2. 7.3 includes/sources.archivesource.inc \backup_migrate_files_destination_archivesource::_restore_from_file_php()

Restore to this source.

Overrides backup_migrate_destination_filesource::_restore_from_file_php

File

includes/sources.archivesource.inc, line 182
A destination type for saving locally to the server.

Class

backup_migrate_files_destination_archivesource
A destination type for saving locally to the server.

Code

function _restore_from_file_php($file, &$settings) {
  $success = false;
  if ($this
    ->check_libs()) {
    $from = $file
      ->pop_type();
    $temp = backup_migrate_temp_directory();
    $tar = new Archive_Tar($from
      ->filepath());
    $tar
      ->extractModify($temp, $file->name);

    // Parse the manifest
    $manifest = $this
      ->read_manifest($temp);

    // Currently only the first site in the archive is supported.
    $site = $manifest['Site 0'];
    $docroot = $temp . '/' . $site['docroot'];
    $sqlfile = $temp . '/' . $site['database-file-default'];
    $filepath = NULL;
    if (isset($site['files-private'])) {
      $filepath = $temp . '/' . $site['files-private'];
    }
    else {
      if (isset($site['files-public'])) {
        $filepath = $temp . '/' . $site['files-public'];
      }
    }

    // Move the files from the temp directory.
    if ($filepath && file_exists($filepath)) {
      _backup_migrate_move_files($filepath, file_directory_path());
    }
    else {
      _backup_migrate_message('Files were not restored because the archive did not seem to contain a files directory or was in a format that Backup and Migrate couldn\'t read', array(), 'warning');
    }

    // Restore the sql db.
    if ($sqlfile && file_exists($sqlfile)) {
      $db_settings = drupal_clone($settings);
      $db_settings->source_id = 'db';
      $file = new backup_file(array(
        'filepath' => $sqlfile,
      ));
      $success = backup_migrate_filters_restore($file, $db_settings);
    }
    else {
      _backup_migrate_message('The database was not restored because the archive did not seem to contain a database backup or was in a format that Backup and Migrate couldn\'t read', array(), 'warning');
    }
    if ($docroot) {
      _backup_migrate_message('Backup and Migrate cannot restore the php code of the site for security reasons. You will have to copy the code to the server by hand if you wish to restore the full site.', array(), 'warning');
    }
    return $success && $file;
  }
  return FALSE;
}