You are here

protected function CompressionFilter::_ZipEncode in Backup and Migrate 8.4

Zip encode a file.

Parameters

\BackupMigrate\Core\File\BackupFileReadableInterface $from:

\BackupMigrate\Core\File\BackupFileWritableInterface $to:

Return value

bool

1 call to CompressionFilter::_ZipEncode()
CompressionFilter::afterBackup in lib/backup_migrate_core/src/Filter/CompressionFilter.php
Run on a backup.

File

lib/backup_migrate_core/src/Filter/CompressionFilter.php, line 307

Class

CompressionFilter
Class CompressionFilter.

Namespace

BackupMigrate\Core\Filter

Code

protected function _ZipEncode(BackupFileReadableInterface $from, BackupFileWritableInterface $to) {
  $success = FALSE;
  if (class_exists('ZipArchive')) {
    $zip = new \ZipArchive();
    $res = $zip
      ->open(drupal_realpath($to
      ->realpath()), constant("ZipArchive::CREATE"));
    if ($res === TRUE) {
      $zip
        ->addFile(drupal_realpath($from
        ->realpath()), $from
        ->getFullName());
    }
    $success = $zip
      ->close();
  }

  // Get the compressed filesize and set it.
  $fileszc = filesize(drupal_realpath($to
    ->realpath()));
  $to
    ->setMeta('filesize', $fileszc);
  return $success;
}