You are here

function drush_getlocations_geojson in Get Locations 7

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

Command to download the GeoJSON javascript library.

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

File

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

Code

function drush_getlocations_geojson() {
  $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_GEOJSON_DOWNLOAD_URI;
  $dirname = 'GeoJSON';

  // 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 GeoJSON library was deleted from @path', array(
        '@path' => $path,
      )), 'notice');
    }

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

    // Change the directory name to "GeoJSON" if needed.
    if (is_dir('geojson-google-maps-master')) {
      drush_move_dir('geojson-google-maps-master', $dirname, TRUE);
    }
  }
  if ($filepath && is_dir($dirname)) {
    drush_log(dt('GeoJSON javascript library has been installed in @path', array(
      '@path' => $path,
    )), 'success');
  }
  else {
    drush_log(dt('Drush was unable to install the GeoJSON javascript library to @path', array(
      '@path' => $path,
    )), 'error');
  }

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