-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathstanford_capx.install
487 lines (450 loc) · 13.3 KB
/
stanford_capx.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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
<?php
/**
* @file
*/
use CAPx\Drupal\Util\CAPxMapper;
/**
* Implements hook_install().
*/
function stanford_capx_install() {
stanford_capx_install_encrypt_settings();
}
/**
* Implements hook_uninstall().
*/
function stanford_capx_uninstall() {
variable_del('stanford_capx_batch_limit');
variable_del('stanford_capx_username');
variable_del('stanford_capx_password');
variable_del('stanford_capx_api_base_url');
variable_del('stanford_capx_api_auth_uri');
variable_del('stanford_capx_admin_messages');
variable_del('stanford_capx_token');
variable_del("capx_last_orgs_sync");
variable_del("capx_last_schema_sync");
variable_del("stanford_capx_debug_always_force_etag");
variable_del("stanford_capx_autotruncate_textfields");
}
/**
* Implements hook_schema().
*/
function stanford_capx_schema() {
$schema = array();
// Profile Information Table.
$schema['capx_profiles'] = array(
'description' => 'CAPx Profile Information.',
'fields' => array(
'id' => array(
'description' => 'The primary identifier for this table.',
'type' => 'serial',
'not null' => TRUE,
),
'entity_type' => array(
'description' => 'The entity type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'bundle_type' => array(
'description' => 'The bundle type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'importer' => array(
'description' => 'The importer machine name.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'entity_id' => array(
'description' => 'The entity ID.',
'type' => 'int',
'default' => 0,
),
'profile_id' => array(
'description' => 'The profile ID from CAP.',
'type' => 'int',
'default' => 0,
),
'etag' => array(
'description' => 'Etag.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'guuid' => array(
'description' => 'A guuid that is not the profile id. Used for multiple creation.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'sync' => array(
'description' => 'Does this profile needs to be synced?',
'type' => 'int',
'not null' => FALSE,
'default' => 1,
'size' => 'tiny',
),
'orphaned' => array(
'description' => 'Wether or not the profile has been orphaned',
'type' => 'int',
'not null' => FALSE,
'default' => 0,
'size' => 'tiny',
),
'last_sync' => array(
'description' => 'The last time this profile was successfully updated.',
'type' => 'int',
'default' => 0,
),
),
'primary key' => array('id'),
'indexes' => array(
'bep' => array('bundle_type', 'entity_id', 'profile_id'),
'iep' => array('importer', 'entity_id', 'profile_id'),
),
);
// Configuration Entity.
$schema['capx_cfe'] = array(
'description' => 'The base table for configuration entities.',
'export' => array(
'key' => 'machine_name',
'key name' => 'Machine Name',
'primary key' => 'cfid',
'identifier' => 'cfe',
'default hook' => 'default_capx_cfe',
'admin_title' => 'title',
'can disable' => FALSE,
'object' => 'CFEntity',
'load callback' => 'capx_cfe_load_by_machine_name',
'export type string' => 'export_type',
'api' => array(
'current_version' => 1,
'minimum_version' => 1,
'owner' => 'stanford_capx',
'api' => 'capx_cfe',
),
),
'fields' => array(
'cfid' => array(
'description' => 'The primary identifier for the cfe.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'no export' => TRUE,
),
'machine_name' => array(
'description' => 'The machine-readable name of this type.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
'type' => array(
'description' => 'The type (bundle) of this cfe.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'title' => array(
'description' => 'The title of the cfe.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'uid' => array(
'description' => 'ID of Drupal user creator.',
'type' => 'int',
'not null' => TRUE,
'no export' => TRUE,
),
'created' => array(
'description' => 'The Unix timestamp when the cfe was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'no export' => TRUE,
),
'changed' => array(
'description' => 'The Unix timestamp when the cfe was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'no export' => TRUE,
),
'settings' => array(
'description' => 'The configuration settings',
'type' => 'blob',
'size' => 'big',
'not null' => TRUE,
'serialize' => TRUE,
),
'meta' => array(
'description' => 'Meta data',
'type' => 'blob',
'size' => 'big',
'not null' => TRUE,
'serialize' => TRUE,
),
'status' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0x01,
'size' => 'tiny',
'description' => 'The exportable status of the entity.',
'no export' => TRUE,
),
'module' => array(
'description' => 'The name of the providing module if the entity has been defined in code.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'no export' => TRUE,
),
),
'primary key' => array('cfid'),
);
// CFE Types.
$schema['capx_cfe_type'] = array(
'description' => 'Stores information about all defined cfe types.',
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique task type ID.',
),
'type' => array(
'description' => 'The machine-readable name of this type.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
'label' => array(
'description' => 'The human-readable name of this type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'description' => array(
'description' => 'A brief description of this type.',
'type' => 'text',
'not null' => TRUE,
'size' => 'medium',
'translatable' => TRUE,
),
'status' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0x01,
'size' => 'tiny',
'description' => 'The exportable status of the entity.',
'no export' => TRUE,
),
'module' => array(
'description' => 'The name of the providing module if the entity has been defined in code.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'no export' => TRUE,
),
),
'primary key' => array('id'),
'unique keys' => array(
'type' => array('type'),
),
);
// Storage for organization aliases.
$schema['capx_org_aliases'] = array(
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique ID.',
),
'tid' => array(
'description' => 'ID of the term.',
'type' => 'int',
'not null' => TRUE,
),
'code' => array(
'description' => 'The organization code.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
'alias' => array(
'description' => 'The alias code of the organization code.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
),
'primary key' => array('id'),
'indexes' => array(
'ica' => array('id', 'code', 'alias'),
'itc' => array('id', 'tid', 'code'),
),
);
return $schema;
}
/**
* Implements hook_requirements().
*/
function stanford_capx_requirements($phase) {
$t = get_t();
$requirements = array();
switch ($phase) {
case 'runtime':
// Ensure the modules' private files directory exists and is writable.
if (!variable_get('file_private_path', FALSE)) {
// Display a message to the user that private files dir must be configured.
$summary = $t('The !directory must be configured for the CAPx module to work correctly.',
array('!directory' => l($t('private files directory'), 'admin/config/media/file-system')));
$requirements['stanford_capx'] = array(
'title' => $t('Stanford CAPx'),
'severity' => REQUIREMENT_ERROR,
'value' => $summary,
);
}
break;
}
return $requirements;
}
/**
* Add the guuid field to the capx_profiles table.
*/
function stanford_capx_update_7200() {
$table = "capx_profiles";
$field = "guuid";
$spec = array(
'description' => 'A guuid that is not the profile id. Used for multiple creation.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
);
if (!db_field_exists($table, $field)) {
db_add_field($table, $field, $spec);
}
}
/**
* If auto_nodetitle is enabled we should enable capx_auto_nodetitle.
*/
function stanford_capx_update_7201() {
if (module_exists("auto_nodetitle")) {
module_enable(array("capx_auto_nodetitle"));
}
}
/**
* Resave each mapper so they get the new default config keys.
*/
function stanford_capx_update_7202() {
// When updating from before this to 3.x we need to add fields to prevent
// errors.
stanford_capx_update_7300();
$mappers = CAPxMapper::loadAllMappers();
foreach ($mappers as $mapper) {
$mapper->settings['multiple'] = FALSE;
$mapper->settings['subquery'] = '';
$mapper->settings['guuidquery'] = '';
$mapper->save();
}
}
/**
* Upgrade path from 2.x - 3.x
*/
function stanford_capx_update_7300() {
// db_add_field($table, $field, $spec, $keys_new = array())
$status_spec = array(
'type' => 'int',
'not null' => TRUE,
'default' => 0x01,
'size' => 'tiny',
'description' => 'The exportable status of the entity.',
);
$module_spec = array(
'description' => 'The name of the providing module if the entity has been defined in code.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
);
if (!db_field_exists("capx_cfe", "status")) {
db_add_field("capx_cfe", "status", $status_spec);
}
if (!db_field_exists("capx_cfe", "module")) {
db_add_field("capx_cfe", "module", $module_spec);
}
if (!db_field_exists("capx_cfe_type", "status")) {
db_add_field("capx_cfe_type", "status", $status_spec);
}
if (!db_field_exists("capx_cfe_type", "module")) {
db_add_field("capx_cfe_type", "module", $module_spec);
}
}
/**
* Upgrade path for PHP 7.2 with encrypt. Create and enable the SSL option.
*/
function stanford_capx_update_7301() {
// Encrypt is required so check to see if it is enabled.
if (!module_exists('encrypt')) {
module_enable(['encrypt']);
}
// Migrate the old encryption to the new encryption. You must be on PHP 7.1
// or below for this to work. Once this upgrade hook has been completed you
// may safely upgrade to PHP 7.2.
$username = decrypt(variable_get('stanford_capx_username', ''));
$password = decrypt(variable_get('stanford_capx_password', ''));
// Install the new encrypt settings.
stanford_capx_install_encrypt_settings();
// Save the old credentials with the new method.
variable_set('stanford_capx_username', encrypt($username));
variable_set('stanford_capx_password', encrypt($password));
}
/**
* Upgrade path for PHP 7.2 for those who missed it in 7301.
*/
function stanford_capx_update_7302() {
// We could check the encryption method of the username and password variables
// here, but it's probably not worth the effort.
stanford_capx_update_7301();
}
/**
* Create the encryption settings for use in CAPx.
*/
function stanford_capx_install_encrypt_settings() {
// Set the key if it is not already set.
$key = variable_get("encrypt_drupal_variable_key", NULL);
if (is_null($key)) {
variable_set('encrypt_drupal_variable_key', md5(date("Fjs") + time() + mt_rand()));
}
// Create a new encryption method for this module to use.
$key_name = STANFORD_CAPX_ENCRYPT_PROFILE;
$settings = encrypt_get_config($key_name);
// Config already exists. Continue on.
if (is_array($settings)) {
return;
}
// No config set. Create it.
$settings = [
'enabled' => 1,
'name' => $key_name,
'label' => t('CAPx - AES SSL'),
'description' => t('For the Stanford CAPx module.'),
'method' => 'openssl',
'method_settings' => '',
'provider' => 'drupal_variable',
'provider_settings' => [
'method' => 'variable_contents',
],
];
encrypt_save_config($settings);
// Set this to be the default profile for the Encrypt module.
variable_set('encrypt_default_config', $key_name);
}