You are here

function drush_filedepot_libraries in filedepot 7

Commands to download the filedepot 3rd Party Javascript libraries.

1 call to drush_filedepot_libraries()
drush_filedepot_post_pm_enable in ./filedepot.drush.inc
Implements drush_MODULE_post_COMMAND().

File

./filedepot.drush.inc, line 58
Drush integration for filedepot.

Code

function drush_filedepot_libraries($path = 'sites/all/libraries') {
  if (!drush_shell_exec('unzip')) {
    return drush_set_error(dt('Missing dependency: unzip. Install it before using this command.'));
  }

  // Create the path if it does not exist.
  if (!is_dir($path)) {
    drush_op('mkdir', $path);
    drush_log(dt('Directory @path was created', array(
      '@path' => $path,
    )), 'notice');
  }

  // Set the directory to the download location.
  $olddir = getcwd();
  chdir($path);
  $dir1 = 'html_encoder';
  $dir2 = 'jquery.blockui';

  // Remove any existing filedepot library directories.
  if (is_dir($dir1)) {
    drush_log(dt('A existing filedepot 3rd party javascript libraries were overwritten at @path', array(
      '@path' => "{$path}/{$dir1}",
    )), 'notice');
  }
  if (is_dir($dir2)) {
    drush_log(dt('A existing filedepot 3rd party javascript libraries were overwritten at @path', array(
      '@path' => "{$path}/{$dir2}",
    )), 'notice');
  }

  // Remove any existing filedepot 3rd party javascript libraries archive.
  $filename = basename(filedepot_DOWNLOAD_URI);
  if (is_file($filename)) {
    drush_op('unlink', $filename);
  }

  // Download the zip archive.
  if (!drush_shell_exec('wget ' . filedepot_DOWNLOAD_URI)) {
    drush_shell_exec('curl -O ' . filedepot_DOWNLOAD_URI);
  }
  if (is_file($filename)) {

    // Decompress the zip archive.
    drush_shell_exec('unzip -qq -o ' . $filename);

    // Remove the zip archive.
    drush_op('unlink', $filename);
  }

  // Set working directory back to the previous working directory.
  chdir($olddir);
  if (is_dir($path . '/jquery.blockui') and is_dir($path . '/html_encoder')) {
    drush_log(dt('filedepot 3rd party javascript libraries has been downloaded to @path.', array(
      '@path' => $path,
    )), 'success');
  }
  else {
    drush_log(dt('Drush was unable to download the 3rd party javascript libraries to @path', array(
      '@path' => $path,
    )), 'error');
  }
}