-
Notifications
You must be signed in to change notification settings - Fork 0
/
module_updates.php
103 lines (95 loc) · 2.72 KB
/
module_updates.php
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* @file
* Gets a list of the modules that have updates so you can do them individually
*/
// Paste "drush up -n" Output in here
$up_output = "
Name Installed version Proposed version Status
Administration menu (admin_menu) 6.x-1.8 6.x-1.8 Up to date
Advanced Poll (advpoll) 6.x-1.x-dev 6.x-1.x-dev Update available
Drupal 6.28 6.33 SECURITY UPDATE available
Chaos tools (ctools) 6.x-1.10 6.x-1.11 SECURITY UPDATE available
";
// how you target your site with Drush
$site = 'drush @tg';
// Print out the commands
echo "SECURITY UPDATES\n";
print_up_commands(
$site, $up_output, 'SECURITY UPDATE'
);
echo "Update available\n";
print_up_commands(
$site, $up_output, 'Update available'
);
/**
* Prints out the commands needed to update your modules & core individaully
*
* @param string $site
* The string representation of how you target your site with Drush eg:
* - drush --uri=domain.com
* - drush @domain
* @param string $up_output
* The output form drush up
*
* @param type $string
* The search string to match against
*/
function print_up_commands($site, $up_output, $string) {
$array = explode("\n", $up_output);
foreach ($array as $line) {
if ((strpos($line, $string)) && strpos($line, 'Locked via drush') === FALSE) {
// Get module name from in the brackets
$name = trim(strget($line, '(', ')'));
if (strlen($name) == 0) {
$name = left($line, strpos($line, ' '));
}
if ($name) {
echo $site . ' up ' . $name . "\n";
}
}
}
}
/**
* Returns text by specifying a start and end point
* @param str $str
* The text to search
* @param str $start
* The beginning identifier
* @param str $end
* The ending identifier
*/
function strget($str, $start, $end) {
$str = "|" . $str . "|";
$len = mb_strlen($start);
if (mb_strpos($str, $start) > 0) {
$int_start = mb_strpos($str, $start) + $len;
$temp = right($str, (mb_strlen($str) - $int_start));
$int_end = mb_strpos($temp, $end);
$return = trim(left($temp, $int_end));
return $return;
}
else {
return FALSE;
}
}
/**
* Replacement for ASP right function
* @param str $str
* the string to cut
* @param int $count
* the length to cut
*/
function right($str, $count) {
return mb_substr($str, ($count * -1));
}
/**
* Replacement for ASP left function
* @param str $str
* the string to cut
* @param int $count
* the length to cut
*/
function left($str, $count) {
return mb_substr($str, 0, $count);
}