-
Notifications
You must be signed in to change notification settings - Fork 1
/
rest_oai_pmh.install
195 lines (180 loc) · 4.99 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
<?php
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'],
];
$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 (max length 32) + ':' + Display ID (max length 32)
'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'],
];
$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 (max length 32) + ':' + Display ID (max length 32)
'length' => 65,
'not null' => TRUE,
],
],
'primary key' => ['entity_type', 'entity_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 {rest_oai_pmh_set}.limit to {rest_oai_pmh_set}.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();
}