function bxslider_drush_plugin_setup in BxSlider 8
Command to download the bxSlider plugin.
1 string reference to 'bxslider_drush_plugin_setup'
- bxslider_drush_command in drush/
bxslider.drush.inc - Implements hook_drush_command().
File
- drush/
bxslider.drush.inc, line 50 - Drush integration for bxslider.
Code
function bxslider_drush_plugin_setup() {
$args = func_get_args();
if (!empty($args[0])) {
$path = $args[0];
}
else {
$path = 'libraries';
}
// Create the path if it does not exist.
if (!is_dir($path)) {
drush_op('mkdir', $path);
\Drupal::logger(dt('Directory @path was created', [
'@path' => $path,
]), 'notice');
}
// Set the directory to the download location.
$old_dir = getcwd();
chdir($path);
// Download the zip archive.
if ($file_path = drush_download_file(BXSLIDER_DOWNLOAD_URI)) {
$filename = basename($file_path);
$dir_name = BXSLIDER_DOWNLOAD_PREFIX . basename($file_path, '.zip');
// Remove any existing bxSlider plugin directory.
if (is_dir($dir_name) || is_dir('bxslider')) {
Filesystem::remove($dir_name, TRUE);
Filesystem::remove('bxslider', TRUE);
\Drupal::logger(dt('A existing bxSlider plugin was deleted from @path', [
'@path' => $path,
]), 'notice');
}
// Decompress the zip archive.
drush_tarball_extract($filename);
// Change the directory name to "bxslider" if needed.
if ($dir_name != 'bxslider') {
drush_move_dir($dir_name, 'bxslider', TRUE);
$dir_name = 'bxslider';
}
}
if (is_dir($dir_name)) {
\Drupal::logger(dt('bxSlider plugin has been installed in @path', [
'@path' => $path,
]), 'success');
}
else {
\Drupal::logger(dt('Drush was unable to install the bxSlider plugin to @path', [
'@path' => $path,
]), 'error');
}
// Set working directory back to the previous working directory.
chdir($old_dir);
}