forked from apigeecs/smartdocs_service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmartdocs_service.module
250 lines (244 loc) · 8.08 KB
/
smartdocs_service.module
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?php
/**
* @file
* Code for the Smartdocs Service feature.
*/
include_once 'smartdocs_service.features.inc';
/**
* Implements hook_services_resources
*
* Expose the SmartDocs CRUD operations and Also allow Import and Rendering of SmartDocs Nodes
* @return array
*/
function smartdocs_service_services_resources() {
return array(
'smartdocs' => array(
'operations' => array(
'retrieve' => array(
'help' => 'Retrieve a smartdocs Model',
'file' => array(
'type' => 'inc',
'module' => 'smartdocs_service',
'name' => 'smartdocs_service',
),
'callback' => '_smartdocs_model_resource_retrieve',
'args' => array(
array(
'name' => 'model',
'optional' => FALSE,
'source' => array('path' => 0),
'type' => 'string',
'description' => 'The name of the SmartDocs Model to retrieve',
),
),
'access callback' => 'user_access',
'access arguments' => array('access smartdocs operations using apis'),
),
'create' => array(
'help' => 'Create a SmartDocs Model',
'file' => array(
'type' => 'inc',
'module' => 'smartdocs_service',
'name' => 'smartdocs_service',
),
'callback' => '_smartdocs_model_resource_create',
'args' => array(
array(
'name' => 'name',
'type' => 'string',
'description' => 'Model name',
'source' => array('data' => 'name'),
'optional' => FALSE,
'default' => '<page>'
),
array(
'name' => 'display_name',
'type' => 'string',
'description' => 'Model Display name',
'source' => array('data' => 'display_name'),
'optional' => TRUE,
'default' => '<page>'
),
array(
'name' => 'description',
'type' => 'string',
'description' => 'Model description',
'source' => array('data' => 'description'),
'optional' => TRUE,
'default' => '<page>'
),
),
'access callback' => 'user_access',
'access arguments' => array('access smartdocs operations using apis'),
),
'update' => array(
'help' => 'Update SmartDocs Model Description',
'file' => array(
'type' => 'inc',
'module' => 'smartdocs_service',
'name' => 'smartdocs_service',
),
'callback' => '_smartdocs_model_resource_update',
'args' => array(
array(
'name' => 'model_name',
'optional' => FALSE,
'source' => array('path' => 0),
'type' => 'string',
'description' => 'The name of the model to update',
),
array(
'name' => 'display_name',
'type' => 'string',
'description' => 'Model Display name',
'source' => array('data' => 'display_name'),
'optional' => TRUE,
'default' => '<page>'
),
array(
'name' => 'description',
'type' => 'string',
'description' => 'Model description',
'source' => array('data' => 'description'),
'optional' => TRUE,
'default' => '<page>'
),
),
'access callback' => 'user_access',
'access arguments' => array('access smartdocs operations using apis'),
),
'delete' => array(
'help' => t('Delete a model'),
'file' => array(
'type' => 'inc',
'module' => 'smartdocs_service',
'name' => 'smartdocs_service',
),
'callback' => '_smartdocs_model_resource_delete',
'args' => array(
array(
'name' => 'model',
'optional' => FALSE,
'source' => array('path' => 0),
'type' => 'string',
'description' => 'The name of the model to delete',
),
),
'access callback' => 'user_access',
'access arguments' => array('access smartdocs operations using apis'),
),
'index' => array(
'help' => 'List all nodes',
'file' => array(
'type' => 'inc',
'module' => 'smartdocs_service',
'name' => 'smartdocs_service',
),
'callback' => '_smartdocs_model_resource_index',
'args' => array(),
'access callback' => 'user_access',
'access arguments' => array('access smartdocs operations using apis'),
),
),
'actions' => array(
'queue_status' => array(
'help' => 'Status of the SmartDocs Queue',
'file' => array(
'type' => 'inc',
'module' => 'smartdocs_service',
'name' => 'smartdocs_service',
),
'callback' => '_smartdocs_service_queue_status',
'access callback' => 'user_access',
'access arguments' => array('access smartdocs operations using apis'),
'access arguments append' => FALSE,
'args' => array(),
),
),
'targeted_actions' => array(
'render' => array(
'help' => 'Render SmartDocs page',
'file' => array(
'type' => 'inc',
'module' => 'smartdocs_service',
'name' => 'smartdocs_service',
),
'callback' => '_smartdocs_service_swagger_render',
'access callback' => 'user_access',
'access arguments' => array('access smartdocs operations using apis'),
'access arguments append' => FALSE,
'args' => array(
array(
'name' => 'model',
'optional' => FALSE,
'source' => array('path' => 0),
'type' => 'string',
'description' => 'The name of the model on which the swagger file should be imported',
),
),
),
'import' => array(
'help' => 'Import Swagger file. POST multipart/form-data',
'file' => array(
'type' => 'inc',
'module' => 'smartdocs_service',
'name' => 'smartdocs_service',
),
'callback' => '_smartdocs_service_swagger_import',
'access callback' => 'user_access',
'access arguments' => array('access smartdocs operations using apis'),
'args' => array(
array(
'name' => 'model',
'optional' => FALSE,
'source' => array('path' => 0),
'type' => 'string',
'description' => 'The name of the model on which the swagger file should be imported',
),
array(
'name' => 'api_definition',
'optional' => TRUE,
'source' => 'data',
'description' => 'The file parameters',
'type' => 'array',
),
),
),
),
)
);
}
/**
* Implemenents hook_permission
* @return array
*/
function smartdocs_service_permission() {
return array(
'access smartdocs operations using apis' => array(
'title' => t('SmartDocs Operations using Services module')
),
);
}
/**
* Implements hook_cron_queue_info()
*
* Queue for processing the SmartDocs Nodes rendering
*/
function smartdocs_service_cron_queue_info() {
$queues['smartdocs_service_queue'] = array(
'worker callback' => 'smartdocs_service_queue_process',
'time' => 60,
);
return $queues;
}
/**
* Worker callback for the smartdocs_service_queue queue.
* @param $item
*/
function smartdocs_service_queue_process($item){
$context = array();
require_once drupal_get_path('module', 'smartdocs') . '/batch/smartdocs.render.inc';
require_once DRUPAL_ROOT . "/includes/batch.inc";
$item[1][] = &$context; //Empty context object added
call_user_func_array($item[0], $item[1]);
}