You are here

protected function WebformExporterBase::addToTarArchive in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/WebformExporterBase.php \Drupal\webform\Plugin\WebformExporterBase::addToTarArchive()

Add file, directory, or content to Tar archive.

Parameters

string $path: System path or file content.

string $name: Archive path or file name (applies to file content).

array $options: Zip file options.

1 call to WebformExporterBase::addToTarArchive()
WebformExporterBase::addToArchive in src/Plugin/WebformExporterBase.php
Add file, directory, or content to exporter archive.

File

src/Plugin/WebformExporterBase.php, line 390

Class

WebformExporterBase
Provides a base class for a results exporter.

Namespace

Drupal\webform\Plugin

Code

protected function addToTarArchive($path, $name, array $options = []) {
  if (!isset($this->archive)) {
    $this->archive = new \Archive_Tar($this
      ->getArchiveFilePath(), 'gz');
  }
  if (@file_exists($path)) {
    if (is_dir($path)) {

      // Add directory to Tar archive.
      $this->archive
        ->addModify((array) $path, $name, $options['remove_path']);
    }
    else {

      // Add file to Tar archive.
      $this->archive
        ->addModify((array) $path, $name, $options['remove_path']);
    }
  }
  else {

    // Add text to Tar archive.
    $this->archive
      ->addString($name, $path);
  }

  // Reset the Tar archive.
  // @see \Drupal\webform\WebformSubmissionExporter::writeExportToArchive
  if (!empty($options['close'])) {
    $this->archive = NULL;
  }
}