forked from cyberwolf/cnapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cnapi.install
409 lines (385 loc) · 12.3 KB
/
cnapi.install
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
<?php
/**
* @file
* Install, update and uninstall functions for the CultuurNet API module.
*/
/**
* Implements hook_schema().
*/
function cnapi_schema() {
// cache_cnapi
$schema['cache_cnapi'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_cnapi']['description'] = 'Cache table for the CNAPI module to store parsed API requests (lists, summaries and reports), identified by an ID generated by cnapi_cache_cid based on the $request for the request.';
// cache_cnapi_detail
$schema['cache_cnapi_detail'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_cnapi_detail']['description'] = 'Cache table for the CNAPI module to store parsed API requests (details), identified by an ID generated by cnapi_cache_cid based on the $request for the request.';
// output types
$schema['cnapi_output_type'] = array(
'description' => 'Output types for the CultuurNet API.',
'fields' => array(
'tid' => array(
'description' => 'The primary identifier for an output type.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE
),
'region_dimension' => array(
'description' => 'Region dimension to use.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE
),
'name' => array(
'description' => 'Output type name.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => ''
),
),
'primary key' => array('tid'),
);
// locations
$schema['cnapi_location'] = array(
'description' => 'Locations for the CultuurNet API.',
'fields' => array(
'lid' => array(
'description' => 'The primary identifier for a location.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => ''
),
'type' => array(
'description' => 'Location type: region or city.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => ''
),
'zip' => array(
'description' => 'Location ZIP.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE
),
'name' => array(
'description' => 'Location name.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => ''
),
'did' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
'description' => 'The dimension of this location.',
),
),
'indexes' => array(
'type' => array('type'),
'zip' => array('zip'),
'did' => array('did'),
),
'primary key' => array('lid'),
);
// locations
$schema['cnapi_location_hierarchy'] = array(
'description' => 'Hierarchy of the locations for the CultuurNet API.',
'fields' => array(
'lid' => array(
'description' => 'The primary identifier for a location.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => ''
),
'pid' => array(
'description' => 'ID of the parent location (0 if no parent).',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => ''
),
),
'indexes' => array(
'pid' => array('pid'),
),
'primary key' => array('lid', 'pid'),
);
// headings
$schema['cnapi_heading'] = array(
'description' => t('Headings for the CultuurNet API.'),
'fields' => array(
'hid' => array(
'description' => 'The primary identifier for a heading.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE
),
'pid' => array(
'description' => 'ID of the parent heading (0 if no parent).',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0
),
'tid' => array(
'description' => 'Output type of the heading.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE
),
'name' => array(
'description' => 'Heading name.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => ''
),
'weight' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
'description' => 'The weight of this heading in relation to other headings.',
),
),
'indexes' => array(
'tid' => array('tid'),
'pid' => array('pid'),
),
'primary key' => array('hid'),
);
// dimension
$schema['cnapi_dimension'] = array(
'description' => 'Dimensions of categories for the CultuurNet API.',
'fields' => array(
'did' => array(
'description' => 'The primary identifier for a dimension.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE
),
'machinename' => array(
'description' => 'Machine name of the dimension (used in API filtes).',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => ''
),
'name' => array(
'description' => 'Dimension name.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => ''
),
),
'primary key' => array('did'),
);
// categories
$schema['cnapi_category'] = array(
'description' => 'Categories for the CultuurNet API.',
'fields' => array(
'cid' => array(
'description' => 'The primary identifier for a category.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => ''
),
'name' => array(
'description' => 'Category name.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => ''
),
'did' => array(
'description' => 'Dimension of the category.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
),
),
'indexes' => array(
'did' => array('did'),
),
'primary key' => array('cid'),
);
// heading category
$schema['cnapi_heading_category'] = array(
'description' => 'What categories a heading is constructed of for the CultuurNet API.',
'fields' => array(
'hid' => array(
'description' => 'The primary identifier for a heading.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE
),
'cid' => array(
'description' => 'The primary identifier for a category.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => ''
),
),
'indexes' => array(
'hid' => array('hid'),
'cid' => array('cid'),
),
);
// categories
$schema['cnapi_actor'] = array(
'description' => 'Actors for the CultuurNet API.',
'fields' => array(
'cdbid' => array(
'description' => 'The primary identifier for an actor.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => ''
),
'name' => array(
'description' => 'Actor name.',
'type' => 'varchar',
'length' => 256,
'not null' => TRUE,
'default' => ''
),
'zip' => array(
'description' => 'Actor ZIP.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE
),
'city' => array(
'description' => 'Actor city.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => ''
),
),
'indexes' => array(
'cdbid' => array('cdbid'),
),
'primary key' => array('cdbid'),
);
return $schema;
}
function cnapi_uninstall() {
$variables = array(
'cnapi_api_location',
'cnapi_api_key',
'cnapi_api_output_type',
'cnapi_lib_version',
'cnapi_proxy_enabled',
'cnapi_proxy_server',
'cnapi_proxy_port',
'cnapi_proxy_username',
'cnapi_proxy_password',
'cnapi_defaults',
'cnapi_defaults_events',
'cnapi_defaults_productions',
'cnapi_defaults_actors',
'cnapi_cache_status',
'cnapi_cache_lifetime',
'cnapi_cache_lifetime_detail',
'cnapi_cache_lifetime_production',
);
foreach ($variables as $variable) {
variable_del($variable);
}
}
/**
* Implements hook_requirements().
*/
function cnapi_requirements($phase) {
$requirements = array();
$t = get_t();
// Verify curl is installed
$has_curl = function_exists('curl_init');
$requirements['curl'] = array(
'title' => $t('cURL'),
'value' => $has_curl ? $t('Enabled') : $t('Not found'),
);
if (!$has_curl) {
$requirements['curl']['severity'] = REQUIREMENT_ERROR;
$requirements['curl']['description'] = $t('CultuurNet API could not be installed because the PHP <a href="@curl_url">cURL</a> library is not available.', array('@curl_url' => 'http://php.net/manual/en/curl.setup.php'));
}
if ($phase == 'runtime') {
// Raise warning if CultuurNet API key has not been set yet.
$requirements['cnapi_api_key']['title'] = $t('CultuurNet API key');
if (trim(variable_get('cnapi_api_key', '')) == '') {
$requirements['cnapi_api_key']['description'] = $t('Your CultuurNet API key has not been set yet. Please configure its settings from the <a href="@url">CultuurNet API settings page</a>.', array('@url' => url('admin/config/services/cnapi')));
$requirements['cnapi_api_key']['severity'] = REQUIREMENT_ERROR;
$requirements['cnapi_api_key']['value'] = $t('Not configured');
}
else {
$requirements['cnapi_api_key']['value'] = variable_get('cnapi_api_key', '');
}
// Raise warning if CultuurNet API location has not been set yet.
$requirements['cnapi_api_location']['title'] = $t('CultuurNet API location');
if (trim(variable_get('cnapi_api_location', CNAPI_API_LOCATION)) == '') {
$requirements['cnapi_api_location']['description'] = $t('The location of the CultuurNet API has not been set yet. Please configure its settings from the <a href="@url">CultuurNet API settings page</a>.', array('@url' => url('admin/config/services/cnapi')));
$requirements['cnapi_api_location']['severity'] = REQUIREMENT_ERROR;
$requirements['cnapi_api_location']['value'] = $t('Not configured');
}
else {
$requirements['cnapi_api_location']['value'] = variable_get('cnapi_api_location', CNAPI_API_LOCATION);
}
// Raise warning if CultuurNet API lib version has not been set yet.
$requirements['cnapi_lib_version']['title'] = $t('CultuurNet API library version');
if (trim(variable_get('cnapi_lib_version', '')) == '') {
$requirements['cnapi_lib_version']['description'] = $t('The CultuurNet API library version has not been set yet. Please configure its settings from the <a href="@url">CultuurNet API settings page</a>.', array('@url' => url('admin/config/services/cnapi')));
$requirements['cnapi_lib_version']['severity'] = REQUIREMENT_ERROR;
$requirements['cnapi_lib_version']['value'] = $t('Not configured');
}
else {
$requirements['cnapi_lib_version']['value'] = variable_get('cnapi_lib_version', '');
}
// Check if locations, headings, ... have been imported
$tables = array(
'cnapi_output_type',
'cnapi_location',
'cnapi_location_hierarchy',
'cnapi_heading',
'cnapi_dimension',
'cnapi_category',
'cnapi_heading_category'
);
$has_empty_table = FALSE;
foreach ($tables as $table) {
$count = db_query('SELECT COUNT(*) FROM {' . $table . '}')->fetchField();
if (!$count) {
$has_empty_table = TRUE;
break;
}
}
$requirements['cnapi_import']['title'] = $t('CultuurNet API import');
if ($has_empty_table) {
$requirements['cnapi_import']['description'] = $t('Locations, headings, ... have not been imported yet. Use "drush cnapi-import-values to import these.');
$requirements['cnapi_import']['severity'] = REQUIREMENT_ERROR;
$requirements['cnapi_import']['value'] = $t('Not imported');
}
else {
$requirements['cnapi_import']['value'] = $t('Imported');
}
}
return $requirements;
}
/**
* Install the schema for actors upgrading.
*/
function cnapi_update_7001() {
if (!db_table_exists('cnapi_actor')) {
$schema = cnapi_schema();
db_create_table('cnapi_actor', $schema['cnapi_actor']);
}
}