You are here

function drush_getlocations_leaflet in Get Locations 7

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

Command to download the Leafletjs library.

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

File

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

Code

function drush_getlocations_leaflet() {
  $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_DOWNLOAD_URI;

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

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

    // Decompress the zip archive
    drush_tarball_extract($filename, $dirname);
  }
  if (is_dir($dirname)) {
    drush_log(dt('Leafletjs library has been installed in @path', array(
      '@path' => $path,
    )), 'success');
  }
  else {
    drush_log(dt('Drush was unable to install the Leafletjs library to @path', array(
      '@path' => $path,
    )), 'error');
  }

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