public function ExportEntityWriter::archiveFiles in Content Synchronizer 8
Same name and namespace in other branches
- 8.2 src/Processors/ExportEntityWriter.php \Drupal\content_synchronizer\Processors\ExportEntityWriter::archiveFiles()
- 3.x src/Processors/ExportEntityWriter.php \Drupal\content_synchronizer\Processors\ExportEntityWriter::archiveFiles()
Zip the generated files.
File
- src/
Processors/ ExportEntityWriter.php, line 149
Class
- ExportEntityWriter
- Export entity writer.
Namespace
Drupal\content_synchronizer\ProcessorsCode
public function archiveFiles() {
$path = \Drupal::service('file_system')
->realpath($this
->getDirPath());
$zip = new ZipArchive();
$zip
->open($path . '/' . $this->slugifier
->slugify($this->id) . self::EXPORT_EXTENSION, ZIPARCHIVE::CREATE);
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::CURRENT_AS_FILEINFO));
foreach ($files as $file) {
if (!in_array($file
->getFilename(), [
'.',
'..',
])) {
$relativePath = str_replace($path . '/', '', $file);
if ($file
->isDir()) {
$zip
->addEmptyDir($relativePath . '/');
}
else {
$zip
->addFromString($relativePath, $file
->getContents());
}
}
}
$zip
->close();
}