You are here

protected function Minisite::processArchive in Mini site 8

Process archive by extracting files and filling-in assets information.

1 call to Minisite::processArchive()
Minisite::setArchiveFile in src/Minisite.php
Set archive file.

File

src/Minisite.php, line 238

Class

Minisite
Class Minisite.

Namespace

Drupal\minisite

Code

protected function processArchive() {
  $asset_directory = $this
    ->prepareAssetDirectory();

  // Scan directory for previously extracted files.
  // Note that we are not checking if _all_ files from archive exist: if any
  // were removed - the archive file would need to be re-uploaded to have
  // the files re-extracted.
  $files = LegacyWrapper::scanDirectory($asset_directory, '/.*/');
  if (!$files) {

    // Files do not exist - looks like this is a first time processing, so
    // we need to extract files. At this point, the archive file has already
    // been validated, so it is a matter of extracting files.
    $archiver = self::getArchiver($this->archiveFile
      ->getFileUri());
    $archiver
      ->listContents();
    $archiver
      ->extract($asset_directory);

    // Re-scan files directory.
    $files = LegacyWrapper::scanDirectory($asset_directory, '/.*/');
  }
  $this->assetContainer = new AssetContainer();
  foreach (array_keys($files) as $file_uri) {

    // Refactor to pass an entity instead of it's fields.
    $this->assetContainer
      ->add($this->entityType, $this->entityBundle, $this->entityId, $this->entityLanguage, $this->fieldName, $file_uri);
  }
  if (!empty($this->aliasPrefix)) {
    $this->assetContainer
      ->updateAliases($this->aliasPrefix);
  }
}