Skip to content
Snippets Groups Projects
Commit 43121cda authored by Nick Dickinson-Wilde's avatar Nick Dickinson-Wilde
Browse files

Issue #3332000 by NickDickinsonWilde: drush dl-cycle-lib doesn't download files

parent f372e226
Branches
Tags
No related merge requests found
<?php
declare(strict_types = 1);
namespace Drupal\views_slideshow_cycle\Commands;
use Drush\Commands\DrushCommands;
use Drush\Drush;
/**
* Drush commands for Views Slideshow Cycle.
......@@ -49,7 +50,7 @@ class ViewsSlideshowCycleCommands extends DrushCommands {
public function downloadHoverIntent() {
$this->installLibrary(
'jQuery HoverIntent',
'libraries/jquery.hoverIntent',
'libraries/jquery.hover-intent',
'jquery.hoverIntent.js',
'https://raw.githubusercontent.com/briancherne/jquery-hoverIntent/master/jquery.hoverIntent.js'
);
......@@ -87,8 +88,17 @@ class ViewsSlideshowCycleCommands extends DrushCommands {
/**
* Helper function to download a library in the given directory.
*
* @param string $name
* The user friendly name of the download.
* @param string $path
* The directory to download to.
* @param string $filename
* The filename to expect.
* @param string $url
* The url to download the file from.
*/
protected function installLibrary($name, $path, $filename, $url) {
protected function installLibrary(string $name, string $path, string $filename, string $url): void {
// Create the path if it does not exist.
if (!is_dir($path)) {
drush_op('mkdir', $path, 0755, TRUE);
......@@ -98,7 +108,7 @@ class ViewsSlideshowCycleCommands extends DrushCommands {
// Be sure we can write in the directory.
$perms = substr(sprintf('%o', fileperms($path)), -4);
if ($perms !== '0755') {
Drush::process('chmod 755 ' . $path);
$this->processManager()->process(['chmod', 755, $path])->start();
}
else {
$perms = NULL;
......@@ -112,16 +122,19 @@ class ViewsSlideshowCycleCommands extends DrushCommands {
'@name' => $name,
]));
}
elseif (drush_op('chdir', $path) && Drush::process('wget ' . $url)) {
$download = $this->processManager()->process(['wget', $url], $path);
$download->start();
if ($download->wait() === 0) {
$this->logger()->success(dt('The latest version of @name has been downloaded to @path', [
'@name' => $name,
'@path' => $path,
]));
}
else {
$this->logger()->warning(dt('Drush was unable to download the @name library to @path', [
$this->logger()->warning(dt('Drush was unable to download the @name library to @path, error: @error', [
'@name' => $name,
'@path' => $path,
'@error' => $download->getErrorOutput(),
]));
}
......@@ -129,7 +142,7 @@ class ViewsSlideshowCycleCommands extends DrushCommands {
// Restore the previous permissions.
if ($perms) {
Drush::process('chmod ' . $perms . ' ' . $path);
$this->processManager()->process(['chmod', $perms, $path])->start();
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment