You are here

protected function MolliePaymentInstaller::extractArchive in Mollie Payment 7.2

Unpacks a downloaded archive file.

We duplicate update_manager_archive_extract() since we do not want this module to depend on the Update manager module.

Parameters

$file: The filename of the archive you wish to extract.

$directory: The directory you wish to extract the archive into.

Return value

\ArchiverInterface The Archiver object used to extract the archive.

Throws

\Exception

1 call to MolliePaymentInstaller::extractArchive()
MolliePaymentInstaller::installMollieApiClient in includes/mollie_payment.installer.inc
Installs the Mollie API client for PHP.

File

includes/mollie_payment.installer.inc, line 351

Class

MolliePaymentInstaller
Class MolliePaymentInstaller.

Namespace

Drupal\mollie_payment

Code

protected function extractArchive($file, $directory) {
  $archiver = archiver_get_archiver($file);
  if (!$archiver) {
    throw new \Exception(t('Cannot extract %file, not a valid archive.', array(
      '%file' => $file,
    )));
  }

  // Remove the directory if it exists, otherwise it might contain a mixture of
  // old files mixed with the new files (e.g. in cases where files were removed
  // from a later release).
  $files = $archiver
    ->listContents();

  // Unfortunately, we can only use the directory name to determine the project
  // name. Some archivers list the first file as the directory (i.e., MODULE/)
  // and others list an actual file (i.e., MODULE/README.TXT).
  $project = strtok($files[0], '/\\');
  $extract_location = $directory . '/' . $project;
  if (file_exists($extract_location)) {
    file_unmanaged_delete_recursive($extract_location);
  }
  $archiver
    ->extract($directory);
  return $archiver;
}