form_placeholder.drush.inc
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* @file
* Drush integration for Form Placeholder.
*/
/**
* Implements hook_drush_command().
*/
function form_placeholder_drush_command() {
$items = array();
// The key in the $items array is the name of the command.
$items['download-placeholder-library'] = array(
'callback' => 'drush_download_placeholder_library',
'description' => dt('Download and install the jquery.placeholder plugin.'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, // No bootstrap.
'arguments' => array(
'path' => dt('Optional. A path where to install the jQuery Placeholder plugin. If omitted Drush will use the default location.'),
),
);
return $items;
}
/**
* Command to download the jQuery Placeholder plugin.
*/
function drush_download_placeholder_library() {
if (!module_exists('libraries')) {
return drush_log(dt("Libraries module doesn't exists."), 'error');
}
$args = func_get_args();
if (!empty($args[0])) {
$path = $args[0];
}
else {
$path = 'sites/all/libraries';
}
// Create the path if it does not exist.
if (!is_dir($path)) {
drush_op('mkdir', $path);
drush_log(dt('Directory @path was created', array('@path' => $path)), 'notice');
}
// Set the directory to the download location.
$olddir = getcwd();
chdir($path);
$placeholder_library = libraries_info('jquery.placeholder');
if ($filepath = drush_download_file($placeholder_library['download url'])) {
$filename = basename($filepath);
$dirname = 'jquery-placeholder-' . $placeholder_library['version'];
// Remove any existing jQuery Placeholder plugin directory
if (is_dir($dirname) || is_dir('jquery.placeholder')) {
drush_delete_dir($dirname, TRUE);
drush_delete_dir('jquery.placeholder', TRUE);
drush_log(dt('A existing jQuery Placeholder plugin was deleted from @path', array('@path' => $path)), 'notice');
}
// Decompress the zip archive
drush_tarball_extract($filename);
// Change the directory name to "jquery.placeholder" if needed.
if ($dirname != 'jquery.placeholder') {
drush_move_dir($dirname, 'jquery.placeholder', TRUE);
$dirname = 'jquery.placeholder';
}
}
if (is_dir($dirname)) {
drush_log(dt('jQuery Placeholder plugin has been installed in @path', array('@path' => $path)), 'success');
}
else {
drush_log(dt('Drush was unable to install the jQuery Placeholder plugin to @path', array('@path' => $path)), 'error');
}
// Set working directory back to the previous working directory.
chdir($olddir);
}