function _addressfield_autocomplete_drush_plugin_process in Addressfield Autocomplete 7
A helper function to process the download of the geocomplete plugin.
Parameters
string $version:
string $path:
1 call to _addressfield_autocomplete_drush_plugin_process()
- drush_addressfield_autocomplete_geocomplete_plugin in ./
addressfield_autocomplete.drush.inc - Command to download the Geocomplete plugin.
File
- ./
addressfield_autocomplete.drush.inc, line 67 - Drush integration for addressfield autocomplete.
Code
function _addressfield_autocomplete_drush_plugin_process($version, $path) {
// Create the path if it does not exist.
if (!is_dir($path)) {
if (!drush_op('mkdir', $path)) {
throw new \Exception(sprintf('Directory %s can not be created', $path));
}
drush_log(dt('Directory @path was created', array(
'@path' => $path,
)), 'notice');
}
// Make sure path is writable
if (!is_writable($path)) {
throw new \Exception(sprintf('%s is not writable', $path));
}
// Set the directory to the download location.
chdir($path);
// Try normal path
$filepath = _addressfield_autocomplete_drush_plugin_download($version);
if (!$filepath) {
// Try the path with v prefix
$filepath = _addressfield_autocomplete_drush_plugin_download('v' . $version);
if (!$filepath) {
throw new \Exception('Geocomplete plugin could not be downloaded.');
}
}
// Remove any existing Geocomplete plugin directory.
if (is_dir('geocomplete')) {
drush_delete_dir('geocomplete', TRUE);
drush_log(dt('An existing Geocomplete plugin was deleted from @path', array(
'@path' => $path,
)), 'notice');
}
// Decompress the zip archive.
$filename = basename($filepath);
$listing = drush_tarball_extract($filename, FALSE, TRUE);
if (!$listing || empty($listing[1])) {
throw new \Exception('Geocomplete plugin could not be extracted');
}
$dirname = rtrim($listing[1], '/');
// Change the directory name to "geocomplete" if needed.
if ($dirname != 'geocomplete' && !drush_move_dir($dirname, 'geocomplete', TRUE)) {
throw new \Exception('Geocomplete plugin could not be moved');
}
}