You are here

function drush_getlocations_leaflet_hash in Get Locations 7

Same name and namespace in other branches
  1. 7.2 drush/getlocations.drush.inc \drush_getlocations_leaflet_hash()

Command to download the Leaflet-hash javascript library.

1 string reference to 'drush_getlocations_leaflet_hash'
getlocations_drush_command in drush/getlocations.drush.inc
Implements hook_drush_command().

File

drush/getlocations.drush.inc, line 333
getlocations.drush.inc @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function drush_getlocations_leaflet_hash() {
  $args = func_get_args();
  if (!empty($args[0])) {
    $path = $args[0];
  }
  else {
    $path = 'sites/all/libraries';
  }

  // 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);
  $zip = GETLOCATIONS_LEAFLET_HASH_DOWNLOAD_URI;
  $dirname = 'leaflet-hash';

  // Download the zip archive
  if ($filepath = drush_download_file($zip)) {
    $filename = basename($filepath);

    // Remove any existing directory
    if (is_dir($dirname)) {
      drush_delete_dir($dirname, TRUE);
      drush_log(dt('An existing Leaflet-hash library was deleted from @path', array(
        '@path' => $path,
      )), 'notice');
    }

    // Decompress the zip archive
    drush_tarball_extract($filename);

    // Copy the file into place.
    $src = 'leaflet-hash-master';
    if (is_dir($src)) {
      if (drush_mkdir($dirname)) {
        drush_copy_dir($src . '/leaflet-hash.js', $dirname . '/leaflet-hash.js');
        drush_delete_dir($src);
      }
    }
  }
  if ($filepath && is_dir($dirname)) {
    drush_log(dt('Leaflet-hash javascript library has been installed in @path', array(
      '@path' => $path,
    )), 'success');
  }
  else {
    drush_log(dt('Drush was unable to install the Leaflet-hash javascript library to @path', array(
      '@path' => $path,
    )), 'error');
  }

  // Set working directory back to the previous working directory.
  chdir($olddir);
}