function drush_addtohomescreen in Add to homescreen 8
Same name and namespace in other branches
- 7 addtohomescreen.drush.inc \drush_addtohomescreen()
Command to download the Add to homescreen library.
1 string reference to 'drush_addtohomescreen'
- addtohomescreen_drush_command in ./
addtohomescreen.drush.inc - Implements hook_drush_command().
File
- ./
addtohomescreen.drush.inc, line 47 - Drush integration for addtohomescreen.
Code
function drush_addtohomescreen() {
$args = func_get_args();
if (!empty($args[0])) {
$path = $args[0];
}
else {
$path = 'libraries';
}
// Create the path if it does not exist.
if (!is_dir($path)) {
drush_op('mkdir', $path);
drush_log(dt('Directory @path was created', [
'@path' => $path,
]), 'notice');
}
// Set the directory to the download location.
$olddir = getcwd();
chdir($path);
// Download the zip archive.
if ($filepath = drush_download_file(ADDTOHOMESCREEN_DOWNLOAD_URI)) {
$filename = basename($filepath);
$dirname = ADDTOHOMESCREEN_DOWNLOAD_PREFIX . basename($filepath, '.zip');
// Remove any existing addtohomescreen plugin directory.
if (is_dir($dirname) || is_dir('addtohomescreen')) {
drush_delete_dir($dirname, TRUE);
drush_delete_dir('addtohomescreen', TRUE);
drush_log(dt('A existing addtohomescreen plugin was deleted from @path', [
'@path' => $path,
]), 'notice');
}
// Decompress the zip archive.
drush_tarball_extract($filename);
// Change the directory name to "addtohomescreen" if needed.
if ($dirname != 'addtohomescreen') {
drush_move_dir($dirname, 'addtohomescreen', TRUE);
$dirname = 'addtohomescreen';
}
}
if (is_dir($dirname)) {
drush_log(dt('addtohomescreen plugin has been installed in @path', [
'@path' => $path,
]), 'success');
}
else {
drush_log(dt('Drush was unable to install the addtohomescreen plugin to @path', [
'@path' => $path,
]), 'error');
}
// Set working directory back to the previous working directory.
chdir($olddir);
}