-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwsdata.drush.inc
185 lines (174 loc) · 6.54 KB
/
wsdata.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
/**
* @file
* Drush implementation for the wsconfig module.
*/
/**
* Implementats hook_drush_command().
*/
function wsdata_drush_command() {
$items = array();
$items['wsdata-get-endpoint'] = array(
'description' => dt('Get wsdata endpoint by wsdata config type. This will display the endpoint for the specified type'),
'aliases' => array('wsdge'),
'arguments' => array(
'type' => dt('The type you wish to show the endpoint for, see drush wsdata-list-types.'),
),
'examples' => array(
'drush wsdata-get-endpoint <wsconfig type machine name>' => dt('Get the endpoint for this wsdata config type.'),
),
'drupal dependencies' => array('wsconfig','wsdata'),
);
$items['wsdata-set-endpoint'] = array(
'description' => dt('Set wsdata endpoint by wsdata config type. This will set the endpoints for all wsconfig of the specified type'),
'aliases' => array('wsdse'),
'arguments' => array(
'type' => dt('The type you wish to update, for list, drush wsdata-list-types.'),
'endpoint' => dt('The endpoint.'),
),
'examples' => array(
'drush wsdata-set-endpoint <wsconfig type machine name> "http://endpoint/services/rest' => dt('Set the endpoint to http://endpoint/services/rest for this wsdata config type.'),
),
'drupal dependencies' => array('wsconfig','wsdata'),
);
$items['wsdata-list-types'] = array(
'arguments' => array(),
'description' => dt('Show all WSConfig Types.'),
'examples' => array(
'drush wsdata-list-types' => dt('Show / list summary of all wsdata endpoints.'),
),
'drupal dependencies' => array('wsconfig','wsdata'),
'aliases' => array('wsdl'),
);
$items['wsdata-list'] = array(
'arguments' => array(),
'description' => dt('Show all WSConfigs.'),
'examples' => array(
'drush wsdata-list' => dt('Show / list summary of all WSConfigs.'),
),
'drupal dependencies' => array('wsconfig','wsdata'),
'aliases' => array('wsdlc'),
);
$items['wsdata-type-disable'] = array(
'description' => dt('Disabled a WSConfig Type'),
'aliases' => array('wsdtd'),
'arguments' => array(
'type' => dt('The WSConfig type you want to disable, see drush wsdata-list-types.'),
),
'examples' => array(
'drush wsdata-type-disable <wsconfig type machine name>' => dt('Disable the given wsconfig type.'),
),
'drupal dependencies' => array('wsconfig','wsdata'),
);
$items['wsdata-type-enable'] = array(
'description' => dt('Enable a WSConfig Type'),
'aliases' => array('wsdte'),
'arguments' => array(
'type' => dt('The WSConfig type you want to enable, see drush wsdata-list-types.'),
),
'examples' => array(
'drush wsdata-type-enable <wsconfig type machine name>' => dt('Disable the given wsconfig type.'),
),
'drupal dependencies' => array('wsconfig','wsdata'),
);
return $items;
}
/**
* Implementats of hook_drush_help().
*/
function wsdata_drush_help($section) {
switch ($section) {
case 'drush:wsdata-get-endpoint':
return dt("This command will get the endpoint of your wsconfig entry by the type of the entry.");
case 'drush:wsdata-set-endpoint':
return dt("This command will set the endpoint of your wsconfig entry by the type of the entry. This is useful when changing your server environments.");
case 'drush:wsdata-list-types':
return dt("This command will show pertinent details about wsconfig types including endpoint configured for wsdata.");
}
}
/**
* Drush command callback.
*/
function drush_wsdata_set_endpoint() {
$args = func_get_args();
$type = $args[0];
$endpoint = $args[1];
if (empty($type) or empty($endpoint)) {
return drush_set_error('arguments_invalid', dt('Please specify WSConfig Type and an endpoint. See drush help wsdata-set-endpoint'));
}
$wsconfigtype = wsconfig_type_load($type);
if ($wsconfigtype) {
$wsconfigtype->setEndpoint($endpoint);
wsconfig_type_save($wsconfigtype);
} else {
return drush_set_error('arguments_invalid', dt('WSConfig type !type was not found. Run "drush wsdata-list-types" for a list of available types.', array('!type' => $type)));
}
}
/**
* Get a list of all wsdata configs.
*/
function drush_wsdata_list() {
$wsconfigs = entity_load('wsconfig', FALSE);
$rows[] = array(dt('Name'), dt('Machine Name'), dt('Type'), dt('Method Type'), dt('Method'));
foreach ($wsconfigs as $wsconfig) {
$row = array($wsconfig->title, $wsconfig->name, $wsconfig->type);
foreach ($wsconfig->getOperations() as $method) {
$rows[] = array_merge($row, array($method, $wsconfig->data[$wsconfig->getMethodKey($method)]));
}
}
drush_print_table($rows, TRUE);
}
/**
* Get a list of all wsdata config types.
*/
function drush_wsdata_list_types() {
$types = wsconfig_get_types();
$rows[] = array(dt('Name'), dt('Machine name'), dt('Endpoint'), dt('Connector'), dt('Status'));
foreach ($types as $type) {
$status = $type->isDisabled()? dt('Disabled') : dt('Enabled');
$rows[] = array($type->label, $type->type, $type->data['endpoint'], $type->data['connector'], $status);
}
drush_print_table($rows, TRUE);
}
/**
* Get an endpoint by type.
*/
function drush_wsdata_get_endpoint() {
if ($args = func_get_args()) {
} elseif ( empty($args[0]) ) {
return drush_set_error('arguments_invalid', dt('Machine name of a wsconfig type not provided. See drush help wsdata-get-endpoint'));
}
$wsconfig_type = wsconfig_type_load($args[0]);
if (!$wsconfig_type) {
return drush_set_error('arguments_invalid', dt('WSConfig type !type was not found. Run "drush wsdata-list-types" for a list of available types.', array('!type' => $type)));
}
drush_print($wsconfig_type->data['endpoint']);
}
/**
* Disable a wsconfig type.
*/
function drush_wsdata_type_disable() {
$args = func_get_args();
$type = $args[0];
$wsconfigtype = wsconfig_type_load($type);
if (!$wsconfigtype) {
return drush_set_error('arguments_invalid', dt('WSConfig type !type was not found. Run "drush wsdata-list-types" for a list of available types.', array('!type' => $type)));
}
if (!$wsconfigtype->isDisabled()) {
$wsconfigtype->disable();
}
}
/**
* Enable a wsconfig type.
*/
function drush_wsdata_type_enable() {
$args = func_get_args();
$type = $args[0];
$wsconfigtype = wsconfig_type_load($type);
if (!$wsconfigtype) {
return drush_set_error('arguments_invalid', dt('WSConfig type !type was not found. Run "drush wsdata-list-types" for a list of available types.', array('!type' => $type)));
}
if ($wsconfigtype->isDisabled()) {
$wsconfigtype->enable();
}
}