-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrest_oai_pmh.install
315 lines (294 loc) · 7.98 KB
/
rest_oai_pmh.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
<?php
/**
* @file
* Contains rest_oai_pmh.install.
*/
use Drupal\Core\Database\Database;
/**
* Implements hook_schema().
*/
function rest_oai_pmh_schema() {
$schema = [];
$schema['rest_oai_pmh_record'] = [
'description' => 'Stores the items that will be exposed to OAI-PMH.',
'fields' => [
'entity_type' => [
'description' => 'The entity id of the record',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
],
'entity_id' => [
'description' => 'The entity type of the record',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
],
'created' => [
'description' => 'A timestamp indicating when the record was created',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
],
'changed' => [
'description' => 'A timestamp indicating when the record was last changed',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
],
],
'primary key' => ['entity_type', 'entity_id'],
'indexes' => [
'entity_type' => ['entity_type'],
'created_ts' => ['created'],
'changed_ts' => ['changed'],
],
];
$schema['rest_oai_pmh_set'] = [
'description' => 'Stores the sets that will be exposed to OAI-PMH.',
'fields' => [
'set_id' => [
'description' => 'The setSpec of the set',
'type' => 'varchar',
// We could have a View ID (32 char) + ':' + Display ID (32 char)
'length' => 65,
'not null' => TRUE,
],
'entity_type' => [
'description' => 'The entity type of the set',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
],
'label' => [
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
],
'description' => [
'type' => 'varchar',
'length' => 255,
],
'pager_limit' => [
'description' => 'The pager/limit value for the set as defined by Views',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 10,
],
'view_display' => [
'description' => 'The View Display this set was exposed from',
'type' => 'varchar',
'length' => 255,
],
],
'primary key' => ['set_id'],
'indexes' => [
'entity_type' => ['entity_type'],
],
];
$schema['rest_oai_pmh_member'] = [
'description' => 'Stores which set(s) each record is a member of.',
'fields' => [
'entity_type' => [
'description' => 'The entity type of the record',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
],
'entity_id' => [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
],
'set_id' => [
'type' => 'varchar',
// We could have a View ID (32 char) + ':' + Display ID (32 char)
'length' => 65,
'not null' => TRUE,
],
],
'primary key' => ['entity_type', 'entity_id', 'set_id'],
'indexes' => [
'entity_type' => ['entity_type'],
'entity_target' => ['entity_type', 'entity_id'],
'set_id' => ['set_id'],
],
];
return $schema;
}
/**
* Add the necessary tables to store OAI-PMH data.
*/
function rest_oai_pmh_update_8001() {
$schema = Database::getConnection()->schema();
$tables = rest_oai_pmh_schema();
foreach ($tables as $name => $table) {
if (!$schema->tableExists($name)) {
$schema->createTable($name, $table);
}
}
}
/**
* Update the set_id field length.
*/
function rest_oai_pmh_update_8002() {
$schema = Database::getConnection()->schema();
$field_name = 'set_id';
$field = [
'type' => 'varchar',
'length' => 65,
'not null' => TRUE,
];
$tables = [
'rest_oai_pmh_set',
'rest_oai_pmh_member',
];
foreach ($tables as $table) {
$schema->changeField($table, $field_name, $field_name, $field);
}
}
/**
* Change "limit" column name to "pager_limit" to accomodate Postgres.
*/
function rest_oai_pmh_update_8003() {
$schema = Database::getConnection()->schema();
$table = 'rest_oai_pmh_set';
$old_limit_field = 'limit';
$new_limit_field = 'pager_limit';
if ($schema->fieldExists($table, $old_limit_field)) {
$schema->dropField($table, $old_limit_field);
}
if (!$schema->fieldExists($table, $new_limit_field)) {
$field_spec = [
'description' => 'The pager/limit value for the set as defined by Views',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 10,
];
$schema->addField($table, $new_limit_field, $field_spec);
}
}
/**
* Update storage config for new plugin storage.
*/
function rest_oai_pmh_update_8004() {
$config = \Drupal::service('config.factory')->getEditable('rest_oai_pmh.settings');
switch ($config->get('mapping_source')) {
case 'metatag_dc':
$mapping_source = 'dublin_core_metatag';
break;
default:
$mapping_source = 'dublin_core_rdf';
}
$config->set('metadata_map_plugins', [
'oai_dc' => $mapping_source,
]);
$config->save();
}
/**
* Update storage config for new cache plugin storage.
*/
function rest_oai_pmh_update_8005() {
$config = \Drupal::service('config.factory')->getEditable('rest_oai_pmh.settings');
$config->set('cache_technique', 'liberal_cache');
$config->save();
}
/**
* Update storage config to avoid potentially using dots as config keys.
*/
function rest_oai_pmh_update_8006() {
$config = \Drupal::service('config.factory')->getEditable('rest_oai_pmh.settings');
$old_map_plugin_config = $config->get('metadata_map_plugins');
$new_map_plugin_config = [];
foreach ($old_map_plugin_config as $prefix => $value) {
$new_map_plugin_config[] = [
'label' => $prefix,
'value' => $value,
];
}
$config->set('metadata_map_plugins', $new_map_plugin_config);
$config->save();
}
/**
* Add some misc indexes.
*/
function rest_oai_pmh_update_8007() {
// A copy of the schema at this point in time, chopped down to only the
// relevant fields so such can be referenced when adding the indexes.
$schema = [];
$schema['rest_oai_pmh_record'] = [
'fields' => [
'entity_type' => [
'description' => 'The entity id of the record',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
],
'created' => [
'description' => 'A timestamp indicating when the record was created',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
],
'changed' => [
'description' => 'A timestamp indicating when the record was last changed',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
],
],
];
$schema['rest_oai_pmh_set'] = [
'fields' => [
'entity_type' => [
'description' => 'The entity type of the set',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
],
],
];
$schema['rest_oai_pmh_member'] = [
'fields' => [
'entity_type' => [
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
],
'entity_id' => [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
],
'set_id' => [
'type' => 'varchar',
'length' => 65,
'not null' => TRUE,
],
],
];
// The new indexes to add.
$indexes = [
'rest_oai_pmh_record' => [
'entity_type' => ['entity_type'],
'created_ts' => ['created'],
'changed_ts' => ['changed'],
],
'rest_oai_pmh_member' => [
'entity_type' => ['entity_type'],
'entity_target' => ['entity_type', 'entity_id'],
'set_id' => ['set_id'],
],
'rest_oai_pmh_set' => [
'entity_type' => ['entity_type'],
],
];
$schema_service = Database::getConnection()->schema();
foreach ($indexes as $table => $idx) {
foreach ($idx as $name => $info) {
$schema_service->addIndex($table, $name, $info, $schema[$table]);
}
}
}