public function FileDirectorySource::importFromFile in Backup and Migrate 8.4
Import to this source from the given backup file. This is the main restore function for this source.
Parameters
\BackupMigrate\Core\File\BackupFileReadableInterface $file: The file to read the backup from. It will not be opened for reading
Overrides SourceInterface::importFromFile
1 method overrides FileDirectorySource::importFromFile()
- DrupalSiteArchiveSource::importFromFile in src/
Source/ DrupalSiteArchiveSource.php - Import to this source from the given backup file. This is the main restore function for this source.
File
- lib/
backup_migrate_core/ src/ Source/ FileDirectorySource.php, line 78
Class
- FileDirectorySource
- Class FileDirectorySource.
Namespace
BackupMigrate\Core\SourceCode
public function importFromFile(BackupFileReadableInterface $file) {
if ($directory = $this
->confGet('directory')) {
// Make sure the directory ends in exactly 1 slash:
if (substr($directory, -1) !== '/') {
$directory = $directory . '/';
}
if (!file_exists($directory)) {
throw new BackupMigrateException('The directory %dir does not exist to restore to.', [
'%dir' => $directory,
]);
}
if (!is_writable($directory)) {
throw new BackupMigrateException('The directory %dir cannot be written to because of the operating system file permissions.', [
'%dir' => $directory,
]);
}
if (!($reader = $this
->getArchiveReader())) {
throw new BackupMigrateException('A file directory source requires an archive reader object.');
}
// Check that the file endings match.
if ($reader
->getFileExt() !== $file
->getExtLast()) {
throw new BackupMigrateException('This source expects a .%ext file.', [
'%ext' => $reader
->getFileExt(),
]);
}
$reader
->setArchive($file);
$reader
->extractTo($directory);
$reader
->closeArchive();
return TRUE;
}
return FALSE;
}