forked from SU-SWS/stanford_capx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstanford_capx.install
295 lines (279 loc) · 7.9 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
<?php
/**
* @file
*/
/**
* Implements hook_install().
*/
function stanford_capx_install() {}
/**
* 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.',
'fields' => array(
'cfid' => array(
'description' => 'The primary identifier for the cfe.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => 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,
),
'created' => array(
'description' => 'The Unix timestamp when the cfe was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'changed' => array(
'description' => 'The Unix timestamp when the cfe was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'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,
),
),
'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,
),
) + entity_exportable_schema_fields(),
'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_7100() {
$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' => '',
);
db_add_field($table, $field, $spec);
}