pi_lib.drush.inc in International Phone 3.x
Drush integration for phone_international.
File
drush/pi_lib.drush.inc
View source
<?php
use Symfony\Component\Filesystem\Filesystem;
define('PI_DOWNLOAD_URI', 'https://github.com/jackocnr/intl-tel-input/archive/v17.0.0.zip');
function pi_lib_drush_command() {
$items = [];
$items['pi-plugin'] = [
'callback' => 'drush_pi_lib_plugin',
'description' => dt('Download and install the Phone International(intl-tel-input) plugin.'),
'bootstrap' => DRUSH_BOOTSTRAP_NONE,
'arguments' => [
'path' => dt('Optional. A path where to install the Phone International(intl-tel-input) plugin. If omitted Drush will use the default location.'),
],
'aliases' => [
'piplugin',
],
];
return $items;
}
function pi_lib_drush_help($section) {
switch ($section) {
case 'drush:pi-plugin':
return dt('Download and install the Phone International(intl-tel-input) plugin from https://github.com/jackocnr/intl-tel-input, default location is /libraries.');
}
}
function drush_pi_lib_plugin() {
$args = func_get_args();
if (!empty($args[0])) {
$path = $args[0];
}
else {
$path = 'libraries';
}
if (!is_dir($path)) {
drush_op('mkdir', $path);
\Drupal::logger(dt('Directory @path was created', [
'@path' => $path,
]))
->notice('notice');
}
$olddir = getcwd();
chdir($path);
if ($filepath = drush_download_file(PI_DOWNLOAD_URI)) {
$filename = basename($filepath);
$dirname = basename($filepath, '.zip');
if (is_dir($dirname) || is_dir('intl-tel-input')) {
Filesystem::remove($dirname, TRUE);
Filesystem::remove('intl-tel-input', TRUE);
\Drupal::logger(dt('A existing Phone International(intl-tel-input) plugin was deleted from @path', [
'@path' => $path,
]))
->notice('notice');
}
drush_tarball_extract($filename, $dirname);
if ($dirname != 'intl-tel-input') {
drush_move_dir($dirname, 'intl-tel-input', TRUE);
$dirname = 'intl-tel-input';
}
}
if (is_dir($dirname)) {
\Drupal::logger(dt('Phone International(intl-tel-input) plugin has been installed in @path', [
'@path' => $path,
]))
->info('success');
}
else {
\Drupal::logger(dt('Drush was unable to install the Phone International(intl-tel-input) plugin to @path', [
'@path' => $path,
]))
->error('error');
}
chdir($olddir);
}