View source
<?php
define('SHARIFF_LIBRARY_DOWNLOAD_URI', 'https://github.com/heiseonline/shariff/archive/master.zip');
function shariff_drush_command() {
$items = array();
$items['shariff-library'] = array(
'callback' => 'download_shariff_library',
'description' => dt('Download and install the shariff library.'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => array(
'path' => dt('Optional. A path where to install the Shariff library. If omitted Drush will use the default location.'),
),
'aliases' => array(
'shariff',
),
);
return $items;
}
function shariff_drush_help($section) {
switch ($section) {
case 'drush:shariff-library':
return dt('Download and install the shariff library from https://github.com/heiseonline/shariff/, default location is sites/all/libraries.');
}
}
function download_shariff_library() {
$args = func_get_args();
if (!empty($args[0])) {
$path = $args[0];
}
else {
$path = 'sites/all/libraries';
}
if (!is_dir($path)) {
drush_op('mkdir', $path);
drush_log(dt('Directory @path was created', array(
'@path' => $path,
)), 'notice');
}
$olddir = getcwd();
chdir($path);
if ($filepath = drush_download_file(SHARIFF_LIBRARY_DOWNLOAD_URI)) {
$filename = basename($filepath);
$dirname = basename($filepath, '.zip');
if (is_dir($dirname) || is_dir('shariff')) {
drush_delete_dir($dirname, TRUE);
drush_delete_dir('shariff', TRUE);
drush_log(dt('Existing Shariff library was deleted from @path', array(
'@path' => $path,
)), 'notice');
}
drush_tarball_extract($filename, $dirname);
drush_log($dirname);
if (is_dir('master')) {
drush_move_dir('master/shariff-master', 'shariff', TRUE);
drush_delete_dir('master', TRUE);
}
$dirname = 'shariff';
}
if (is_dir($dirname)) {
drush_log(dt('The Shariff library has been installed in @path', array(
'@path' => $path,
)), 'success');
}
else {
drush_log(dt('Drush was unable to install the Shariff library to @path', array(
'@path' => $path,
)), 'error');
}
chdir($olddir);
}