public function PackageDownloader::download in Ludwig 8
Downloads and places packages into their modules.
Parameters
array $package: The package.
Throws
\Exception
\Drupal\Core\FileTransfer\FileTransferException
Overrides PackageDownloaderInterface::download
File
- src/
PackageDownloader.php, line 91
Class
- PackageDownloader
- Download packages defined in ludwig.json files.
Namespace
Drupal\ludwigCode
public function download(array $package) {
$provider_path = $this->root . '/' . $package['provider_path'];
if (!is_writable($provider_path)) {
throw new \Exception(sprintf('The extension directory %s is not writable.', $provider_path));
}
$archive_path = $this
->downloadArchive($package);
if (!$archive_path) {
throw new \Exception(sprintf('Unable to retrieve %s from %s.', $package['name'], $package['download_url']));
}
$archiver = $this
->extractArchive($archive_path);
$files = $archiver
->listContents();
if (!$files) {
throw new \Exception(sprintf('The archive downloaded from %s contains no files.', $package['download_url']));
}
// The real path the first directory in the extracted archive.
// @todo Will this work for non-GitHub archives?
$source_location = $this->fileSystem
->realpath($this->extractionDir . '/' . $files[0]);
$package_destination = $this->root . '/' . $package['path'];
$file_transfer = new Local($this->root, $this->fileSystem);
$file_transfer
->copyDirectory($source_location, $package_destination);
$new_perms = substr(sprintf('%o', fileperms($package_destination)), -4, -1) . "5";
$file_transfer
->chmod($package_destination, intval($new_perms, 8), TRUE);
}