-
Notifications
You must be signed in to change notification settings - Fork 0
/
brand.drush.inc
148 lines (146 loc) · 5.54 KB
/
brand.drush.inc
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/**
* Implementation of hook_drush_command().
*/
function brand_drush_command() {
$items = array();
$items['brand'] = array(
'callback' => 'brand_drush_execute',
'description' => 'Drush command to get node count of particular node type.',
'examples' => array(
'Add a theme to the allowed themes list' => 'drush brand allow bartik',
'List the machine names for all configured brands' => 'drush brand list',
'Remove a theme from the list of allowed themes' => 'drush brand disallow bartik',
),
'arguments' => array(
'allow' => 'Add a theme into the list of allowed themes.',
'disallow' => 'Remove a theme from the allowed themes.',
'restrict' => 'Imposes the restriction of theme selection to those configured',
'unrestrict' => 'Removes the restriction of available themes configured.',
),
);
return $items;
}
/**
* Callback function for hook_drush_command().
*/
function brand_drush_execute() {
// Get arguments passed in command, Ex: drush nc page blog
$args = func_get_args();
if ($args) {
switch ($args[0]):
case 'allow':
if (isset($args[1])) {
$allowed_themes = brand_get_allowed_themes();
foreach ($allowed_themes as $allowed_theme) {
$themes[$allowed_theme] = $allowed_theme;
}
if (!isset($themes[$args[1]])) {
$real_themes = list_themes();
if (isset($real_themes[$args[1]])) {
$allowed_themes[] = $args[1];
variable_set('brand_allowed_themes', $allowed_themes);
$new_themes = variable_get('brand_allowed_themes', array());
foreach ((array) $new_themes as $new_theme) {
if ($new_theme === $args[1]) {
drush_log("{$args[1]} has successfully been added to the allowed themes list.", 'ok');
}
else {
drush_log("{$args[1]} could not be added to the allowed themes list.", 'error');
}
}
}
else {
drush_log("{$args[1]} doesn't appear to be recognized as a theme by Drupal.", 'error');
}
}
else {
drush_log("{$args[1]} is already in the list of allowed themes.", 'warning');
}
}
else {
drush_log('No theme specified, run \'drush help brand\' for more information.', 'error');
}
break;
case 'disallow':
if (isset($args[1])) {
$allowed_themes = brand_get_allowed_themes();
foreach ($allowed_themes as $allowed_theme) {
$themes[$allowed_theme] = $allowed_theme;
}
if (isset($themes[$args[1]])) {
$real_themes = list_themes();
if (isset($real_themes[$args[1]])) {
foreach ($allowed_themes as $key => $value) {
if ($value === $args[1]) {
unset($allowed_themes[$key]);
}
}
variable_set('brand_allowed_themes', $allowed_themes);
$new_themes = variable_get('brand_allowed_themes', array());
$found = FALSE;
foreach ((array) $new_themes as $new_theme) {
if ($new_theme === $args[1]) {
$found = TRUE;
}
}
if ($found === FALSE) {
drush_log("{$args[1]} has successfully been removed from the allowed themes list.", 'ok');
}
else {
drush_log("{$args[1]} could not be removed from the allowed themes list.", 'error');
}
}
else {
drush_log("{$args[1]} doesn't appear to be recognized as a theme by Drupal.", 'error');
}
}
else {
drush_log("{$args[1]} is not already in the list of allowed themes.", 'warning');
}
}
else {
drush_log('No theme specified, run \'drush help brand\' for more information.', 'error');
}
break;
case 'restrict':
$old_restriction = variable_get('brand_disable_checking', 0);
if ((int) $old_restriction === 0) {
drush_log('Restrictions on theme selection are already imposed.', 'warning');
}
else {
variable_set('brand_disable_checking', 0);
$new_restriction = variable_get('brand_disable_checking', 0);
if ((int) $new_restriction === 0) {
drush_log('Restrictions on theme selection have been imposed.', 'ok');
}
else {
drush_log('Restrictions on theme selection could not be imposed.', 'error');
}
}
break;
case 'unrestrict':
$old_restriction = variable_get('brand_disable_checking', 0);
if ((int) $old_restriction === 1) {
drush_log('Restrictions on theme selection are not imposed.', 'warning');
}
else {
variable_set('brand_disable_checking', 1);
$new_restriction = variable_get('brand_disable_checking', 0);
if ((int) $new_restriction === 1) {
drush_log('Restrictions on theme selection have been lifted.', 'ok');
}
else {
drush_log('Restrictions on theme selection could not be lifted.', 'err');
}
}
break;
default:
drush_log('No argument specified, run \'drush help brand\' for more information.', 'error');
break;
endswitch;
}
else {
drush_log('No argument specified, run \'drush help brand\' for more information.', 'error');
}
}