-
Notifications
You must be signed in to change notification settings - Fork 13
/
islandora_xquery.install
310 lines (300 loc) · 9.19 KB
/
islandora_xquery.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
<?php
/**
* @file
* Defines the install and uninstall hooks for this module.
* @todo
* Factor out association_id and use the machine_name as key.
*/
/**
* Implements hook_schema().
*/
function islandora_xquery_schema() {
$schema['islandora_xquery_associations'] = array(
'description' => 'Table that stores saved template names.',
'fields' => array(
'association_id' => array(
'description' => 'Unique ID given to each association',
'type' => 'serial',
'length' => 11,
'not null' => TRUE,
),
'template_name' => array(
'description' => 'The name of the template',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'template_description' => array(
'description' => 'The description of the template',
'type' => 'text',
'size' => 'medium',
'not null' => FALSE,
),
'machine_name' => array(
'type' => 'varchar',
'length' => 255,
'description' => 'The machine readable name for this association',
'not null' => TRUE,
),
),
'primary key' => array('association_id'),
);
$schema['islandora_xquery_xquery'] = array(
'description' => 'Table that stores XQuery values.',
'fields' => array(
'association_id' => array(
'description' => 'Unique ID given to each association',
'type' => 'int',
'length' => 11,
'not null' => TRUE,
),
'xquery' => array(
'description' => 'Holds the XQuery defined for an association',
'type' => 'blob',
'size' => 'big',
'not null' => TRUE,
),
),
'primary_key' => array('association_id'),
);
$schema['islandora_xquery_tokens'] = array(
'description' => 'Table that stores token information.',
'fields' => array(
'association_id' => array(
'description' => 'Unique ID given to each association',
'type' => 'int',
'length' => 11,
'not null' => TRUE,
),
'token_name' => array(
'description' => 'The name of the token',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'token_description' => array(
'description' => 'The description of the token',
'type' => 'text',
'size' => 'medium',
'not null' => TRUE,
),
'token_default' => array(
'description' => 'The default value of the token',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
),
'primary key' => array('association_id', 'token_name'),
);
$schema['islandora_xquery_diffs'] = array(
'description' => "Table that stores diffs of the xquery results for viewing before user confirmation.",
'fields' => array(
'id' => array(
'description' => "Unique ID",
'type' => 'serial',
'not null' => TRUE,
'unsigned' => TRUE,
),
'batch_id' => array(
'description' => 'ID of batch running the find/replace operation.',
'type' => 'int',
'not null' => TRUE,
),
'pid' => array(
'description' => "PID of object to run find/replace.",
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'dsid' => array(
'description' => "ID of datastream to run find/replace on.",
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'diff' => array(
'description' => "Diff after find/replace.",
'type' => 'blob',
'not null' => TRUE,
),
'status' => array(
'description' => 'Status of find/replace. PENDING, APPLIED, etc...',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => 'PENDING',
),
),
'primary key' => array('id'),
'indexes' => array(
'index_batch_id' => array('batch_id'),
'index_pid' => array('pid'),
'index_dsid' => array('dsid'),
'index_status' => array('status'),
),
);
$schema['islandora_xquery_batches'] = array(
'description' => "Table that stores batch id's and creation timestamps for returning or cleaning up diffs.",
'fields' => array(
'batch_id' => array(
'description' => 'ID of batch running the find/replace operation.',
'type' => 'int',
'not null' => TRUE,
),
'batch_created' => array(
'description' => "Creation time of the find/replace batch.",
'type' => 'int',
'not null' => TRUE,
),
'batch_ended' => array(
'description' => "End time of the find/replace batch.",
'type' => 'int',
'not null' => TRUE,
),
'xquery' => array(
'description' => 'Xquery being applied in this batch',
'type' => 'blob',
'size' => 'big',
'not null' => TRUE,
),
'redirect' => array(
'description' => 'Where to go when the process is finished.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
),
'primary_key' => array('batch_id'),
'indexes' => array(
'index_batch_created' => array('batch_created'),
'index_batch_ended' => array('batch_ended'),
),
);
return $schema;
}
/**
* Implements hook_requirements().
*/
function islandora_xquery_requirements($phase) {
module_load_include('inc', 'islandora_xquery', 'includes/utilities');
$requirements = array();
// Ensure translations don't break during installation.
$t = get_t();
switch ($phase) {
case 'runtime':
$zorba_version = islandora_xquery_get_zorba_version();
$basex_version = islandora_xquery_get_basex_version();
if ($basex_version === FALSE && $zorba_version === FALSE) {
$requirements['xquery_processor'] = array(
'title' => $t('XQuery Processor'),
'value' => $t('Processor could not be found. Islandora XQuery requires Zorba %version or BaseX.', array('%version' => ISLANDORA_XQUERY_ZORBA_REQUIRED_VERSION)),
'severity' => REQUIREMENT_ERROR,
);
}
elseif ($basex_version === FALSE && version_compare($zorba_version, ISLANDORA_XQUERY_ZORBA_REQUIRED_VERSION, '!=')) {
$requirements['xquery_processor'] = array(
'title' => $t('XQuery Processor'),
'value' => $t('Islandora XQuery requires BaseX or Zorba %required_version. Zorba version %version is currently installed.', array(
'%required_version' => ISLANDORA_XQUERY_ZORBA_REQUIRED_VERSION,
'%version' => $zorba_version,
)
),
'severity' => REQUIREMENT_ERROR,
);
}
else {
if ($basex_version !== FALSE) {
$value = "BaseX " . $basex_version;
}
else {
$value = "Zorba " . $zorba_version;
}
$requirements['xquery_processor'] = array(
'title' => $t('XQuery Processor'),
'value' => $value,
'severity' => REQUIREMENT_OK,
);
}
break;
}
return $requirements;
}
/**
* Implements hook_uninstall().
*/
function islandora_xquery_uninstall() {
$variables = array(
'islandora_xquery_zorba',
'islandora_xquery_basex_executable',
'islandora_xquery_implementation',
);
array_walk($variables, 'variable_del');
}
/**
* Preserve default processor for existing installations.
*/
function islandora_xquery_update_7100() {
variable_set('islandora_xquery_implementation', 'zorba');
}
/**
* Update Islandora Xquery Diffs table primary key to not allow NULL values.
*/
function islandora_xquery_update_7101() {
// For sanity, let's make sure there are no null values in the table...
$results = db_select('islandora_xquery_diffs', 'i')
->fields('i', array('id'))
->isNull('id')
->execute()
->rowCount();
if ($results) {
return new DrupalUpdateException('NULL entries found in islandora_xquery_diffs table, please manually correct any rows with NULL values.');
}
else {
db_add_index('islandora_xquery_diffs', 'temp_id_index', array('id'));
db_drop_primary_key('islandora_xquery_diffs');
db_change_field('islandora_xquery_diffs', 'id', 'id', array(
'description' => "Unique ID",
'type' => 'serial',
'not null' => TRUE,
'unsigned' => TRUE,
), array(
'primary key' => array(
'id',
),
));
db_drop_index('islandora_xquery_diffs', 'temp_id_index');
}
}
/**
* Implements hook_update_N().
*
* Updates xquery fields to use big blobs.
*/
function islandora_xquery_update_7102() {
db_change_field('islandora_xquery_xquery', 'xquery', 'xquery', array(
'description' => 'Holds the XQuery defined for an association',
'type' => 'blob',
'size' => 'big',
'not null' => TRUE,
));
db_change_field('islandora_xquery_batches', 'xquery', 'xquery', array(
'description' => 'Xquery being applied in this batch',
'type' => 'blob',
'size' => 'big',
'not null' => TRUE,
));
}
/**
* Implements hook_update_N().
*
* Updates xquery diff field to use big blobs.
*/
function islandora_xquery_update_7103() {
db_change_field('islandora_xquery_diffs', 'diff', 'diff', array(
'description' => "Diff after find/replace.",
'type' => 'blob',
'size' => 'big',
'not null' => TRUE,
));
}