Commit e81a431d authored by frjo's avatar frjo

Updated the Drush command to handle renaming dir colorbox-1.3.18 to colorbox....

Updated the Drush command to handle renaming dir colorbox-1.3.18 to colorbox. Backported improvments from D7 as well.
parent e3bb8b94
...@@ -31,7 +31,7 @@ function colorbox_drush_command() { ...@@ -31,7 +31,7 @@ function colorbox_drush_command() {
// the key in the $items array is the name of the command. // the key in the $items array is the name of the command.
$items['colorbox-plugin'] = array( $items['colorbox-plugin'] = array(
'callback' => 'drush_colorbox_plugin', 'callback' => 'drush_colorbox_plugin',
'description' => dt("Downloads the Colorbox plugin."), 'description' => dt('Download and install the Colorbox plugin.'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, // No bootstrap. 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, // No bootstrap.
'arguments' => array( 'arguments' => array(
'path' => dt('Optional. A path where to install the Colorbox plugin. If omitted Drush will use the default location.'), 'path' => dt('Optional. A path where to install the Colorbox plugin. If omitted Drush will use the default location.'),
...@@ -57,7 +57,7 @@ function colorbox_drush_command() { ...@@ -57,7 +57,7 @@ function colorbox_drush_command() {
function colorbox_drush_help($section) { function colorbox_drush_help($section) {
switch ($section) { switch ($section) {
case 'drush:colorbox-plugin': case 'drush:colorbox-plugin':
return dt("Downloads the Colorbox plugin from colorpowered.com, default location is sites/all/libraries."); return dt('Download and install the Colorbox plugin from jacklmoore.com/colorbox, default location is sites/all/libraries.');
} }
} }
...@@ -75,10 +75,6 @@ function colorbox_drush_help($section) { ...@@ -75,10 +75,6 @@ function colorbox_drush_help($section) {
* Command to download the Colorbox plugin. * Command to download the Colorbox plugin.
*/ */
function drush_colorbox_plugin() { function drush_colorbox_plugin() {
if (!drush_shell_exec('type unzip')) {
return drush_set_error(dt('Missing dependency: unzip. Install it before using this command.'));
}
$args = func_get_args(); $args = func_get_args();
if (!empty($args[0])) { if (!empty($args[0])) {
$path = $args[0]; $path = $args[0];
...@@ -102,32 +98,37 @@ function drush_colorbox_plugin() { ...@@ -102,32 +98,37 @@ function drush_colorbox_plugin() {
// Remove any existing Colorbox plugin directory // Remove any existing Colorbox plugin directory
if (is_dir($dirname)) { if (is_dir($dirname)) {
drush_log(dt('A existing Colorbox plugin was overwritten at @path', array('@path' => $path)), 'notice'); drush_delete_dir($dirname, TRUE);
drush_delete_dir('colorbox', TRUE);
drush_log(dt('A existing Colorbox plugin was deleted from @path', array('@path' => $path)), 'notice');
} }
// Remove any existing Colorbox plugin zip archive // Remove any existing Colorbox plugin zip archive
if (is_file($filename)) { if (is_file($filename)) {
drush_op('unlink', $filename); drush_delete_dir($filename, TRUE);
} }
// Download the zip archive // Download the zip archive
if (!drush_shell_exec('wget '. COLORBOX_DOWNLOAD_URI)) { drush_download_file(COLORBOX_DOWNLOAD_URI);
drush_shell_exec('curl -O '. COLORBOX_DOWNLOAD_URI);
}
if (is_file($filename)) { if (is_file($filename)) {
// Decompress the zip archive // Decompress the zip archive
drush_shell_exec('unzip -qq -o '. $filename); drush_tarball_extract($filename);
// Remove the zip archive
drush_op('unlink', $filename);
} }
// Set working directory back to the previous working directory. // Change the directory name to "colorbox" if needed.
chdir($olddir); if ($dirname != 'colorbox') {
drush_move_dir($dirname, 'colorbox', TRUE);
$dirname = 'colorbox';
}
if (is_dir($path .'/'. $dirname)) { if (is_dir($dirname)) {
drush_log(dt('Colorbox plugin has been downloaded to @path', array('@path' => $path)), 'success'); drush_log(dt('Colorbox plugin has been installed in @path', array('@path' => $path)), 'success');
} }
else { else {
drush_log(dt('Drush was unable to download the Colorbox plugin to @path', array('@path' => $path)), 'error'); drush_log(dt('Drush was unable to install the Colorbox plugin to @path', array('@path' => $path)), 'error');
} }
// Set working directory back to the previous working directory.
chdir($olddir);
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment