View source
<?php
define('CMISPHPLIB_DOWNLOAD_URI', 'https://people.apache.org/~richardm/chemistry/phpclient/0.2.0-RC1/cmis-phplib.zip');
function cmis_drush_command() {
$items = array();
$items['cmis-phplib'] = array(
'callback' => 'drush_cmis_library',
'description' => dt("Downloads the CMIS PHP library."),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => array(
'path' => dt('Optional. A path where to install the PHP CMIS Library plugin. If omitted Drush will use the default location.'),
),
'aliases' => array(
'cmisphplib',
),
);
return $items;
}
function cmis_drush_help($section) {
switch ($section) {
case 'drush:cmis-phplib':
return dt("Downloads the CMIS PHP library from Apache Chemistry, default location is sites/all/libraries.");
}
}
function drush_cmis_library() {
if (!drush_shell_exec('type unzip')) {
return drush_set_error(dt('Missing dependency: unzip. Install it before using this command.'));
}
$args = func_get_args();
if ($args[0]) {
error_log($path);
$path = $args[0];
}
else {
$path = 'sites/all/libraries/cmis-phplib';
}
if (!is_dir($path)) {
drush_op('mkdir', $path);
drush_log(dt('Directory @path was created', array(
'@path' => $path,
)), 'notice');
}
$olddir = getcwd();
chdir($path);
$filename = basename(CMISPHPLIB_DOWNLOAD_URI);
$dirname = basename(CMISPHPLIB_DOWNLOAD_URI, '.zip');
if (is_dir($dirname)) {
drush_log(dt('A existing CMIS PHP library was overwritten at @path', array(
'@path' => $path,
)), 'notice');
}
if (is_file($filename)) {
drush_op('unlink', $filename);
}
if (!drush_shell_exec('wget ' . CMISPHPLIB_DOWNLOAD_URI)) {
drush_shell_exec('curl -O ' . CMISPHPLIB_DOWNLOAD_URI);
}
if (is_file($filename)) {
drush_shell_exec('unzip -qq -o ' . $filename);
drush_op('unlink', $filename);
}
chdir($olddir);
if (is_dir($path . '/' . $dirname)) {
drush_log(dt('Drush was unable to download the PHP CMIS Library to @path', array(
'@path' => $path,
)), 'error');
}
else {
drush_log(dt('PHP CMIS Library plugin has been downloaded to @path', array(
'@path' => $path,
)), 'success');
}
}