public function FileDirectorySource::exportToFile in Backup and Migrate 5.0.x
Export this source to the given temp file.
This should be the main back up function for this source.
Return value
\Drupal\backup_migrate\Core\File\BackupFileReadableInterface A backup file with the contents of the source dumped to it..
Overrides SourceInterface::exportToFile
File
- src/
Core/ Source/ FileDirectorySource.php, line 49
Class
- FileDirectorySource
- @package Drupal\backup_migrate\Core\Source
Namespace
Drupal\backup_migrate\Core\SourceCode
public function exportToFile() {
if ($directory = $this
->confGet('directory')) {
// Make sure the directory ends in exactly 1 slash:
if (substr($directory, -1) !== '/') {
$directory = $directory . '/';
}
if (!($writer = $this
->getArchiveWriter())) {
throw new BackupMigrateException('A file directory source requires an archive writer object.');
}
$ext = $writer
->getFileExt();
$file = $this
->getTempFileManager()
->create($ext);
if ($files = $this
->getFilesToBackup($directory)) {
$writer
->setArchive($file);
foreach ($files as $new => $real) {
$writer
->addFile($real, $new);
}
$writer
->closeArchive();
return $file;
}
throw new BackupMigrateException('The directory %dir does not not have any files to be backed up.', [
'%dir' => $directory,
]);
}
return FALSE;
}