forked from Islandora/islandora_solr_metadata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
islandora_solr_metadata.install
256 lines (245 loc) · 7.7 KB
/
islandora_solr_metadata.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
<?php
/**
* @file
* Implementations of installation hooks.
*/
/**
* Implements hook_schema().
*/
function islandora_solr_metadata_schema() {
$schema['islandora_solr_metadata_associations'] = array(
'description' => 'Table that stores saved configuration names.',
'fields' => array(
'configuration_id' => array(
'description' => 'Unique ID given to each association',
'type' => 'serial',
'length' => 11,
'not null' => TRUE,
),
'configuration_name' => array(
'description' => 'The name of the configuration which this field belongs to',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'description_field' => array(
'type' => 'varchar',
'length' => 255,
'default' => NULL,
'description' => 'The field name as indexed in Solr to be used for displaying description metadata',
),
'description_label' => array(
'type' => 'varchar',
'length' => 255,
'description' => 'The label for the description metadata',
'default' => NULL,
),
'description_data' => array(
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
'description' => 'A serialized array of name value pairs that store extra description field settings.',
),
'machine_name' => array(
'type' => 'varchar',
'length' => 255,
'description' => 'The machine readable name for this association',
'not null' => TRUE,
),
),
'primary key' => array('configuration_id'),
);
$schema['islandora_solr_metadata_fields'] = array(
'description' => 'Table that stores Islandora Solr Metadata field settings.',
'fields' => array(
'configuration_id' => array(
'type' => 'int',
'length' => 11,
'not null' => TRUE,
'description' => 'The ID of the configuration which this field belongs to',
),
'solr_field' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => 'The field name as indexed in Solr',
),
'data' => array(
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
'description' => 'A serialized array of name value pairs that store permissions field settings.',
),
'weight' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Weight of the field within field type.',
),
),
'primary key' => array('configuration_id', 'solr_field'),
);
$schema['islandora_solr_metadata_cmodels'] = array(
'description' => 'Table that stores content models associated to configurations',
'fields' => array(
'configuration_id' => array(
'type' => 'int',
'length' => 11,
'not null' => TRUE,
'description' => 'The ID of the configuration which this field belongs to',
),
'cmodel' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => 'The name of the content model assigned to this configuration',
),
),
'primary_key' => array('configuration_id', 'cmodel'),
);
return $schema;
}
/**
* Implements hook_uninstall().
*/
function islandora_solr_metadata_uninstall() {
$variables = array(
'islandora_solr_metadata_omit_empty_values',
'islandora_solr_metadata_dedup_values',
'islandora_solr_metadata_field_value_separator',
);
array_walk($variables, 'variable_del');
}
/**
* Add the hyperlink column to the database going forward.
*/
function islandora_solr_metadata_update_7100() {
db_add_field('islandora_solr_metadata_fields', 'hyperlink', array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
));
}
/**
* Add additional columns needed to give new configuration options.
*/
function islandora_solr_metadata_update_7101() {
db_add_field('islandora_solr_metadata_fields', 'permissions', array(
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
'description' => 'A serialized array of name value pairs that store permissions field settings.',
));
db_add_field('islandora_solr_metadata_fields', 'date_format', array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'The PHP date format used for dates.',
));
db_add_field('islandora_solr_metadata_fields', 'structured_data', array(
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
'description' => 'A serialized array containing a namespace, prefix and value to be used for marking up data for SEO.',
));
}
/**
* Move columns into new blob.
*/
function islandora_solr_metadata_update_7102() {
$transaction = db_transaction();
db_add_field('islandora_solr_metadata_fields', 'data', array(
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
'description' => 'Serialized associative array with misc display parameters.',
));
$fields_to_remove = drupal_map_assoc(array(
'display_label',
'hyperlink',
'date_format',
'permissions',
'structured_data',
));
$results = db_select('islandora_solr_metadata_fields', 'f')
->fields('f')
->execute();
while ($result = $results->fetchAssoc()) {
db_update('islandora_solr_metadata_fields')
->fields(array('data' => serialize(array_intersect_key($result, $fields_to_remove))))
->condition('configuration_id', $result['configuration_id'])
->condition('solr_field', $result['solr_field'])
->execute();
}
foreach ($fields_to_remove as $field) {
db_drop_field('islandora_solr_metadata_fields', $field);
}
}
/**
* Create a new input format to use for filtering.
*/
function islandora_solr_metadata_update_7103() {
$t = get_t();
$format = filter_format_load('filtered_html');
$format->format = 'islandora_solr_metadata_filtered_html';
$format->name = $t('Islandora Solr Metadata Filtered HTML');
$format->filters = filter_list_format('filtered_html');
foreach ($format->filters as $key => $filter) {
$format->filters[$key] = (array) $filter;
}
$to_exist = array(
'<a>',
'<span>',
);
$tags = $format->filters['filter_html']['settings']['allowed_html'];
foreach ($to_exist as $add) {
if (strpos($tags, $add) === FALSE) {
$tags .= " $add";
}
}
$format->filters['filter_html']['settings']['allowed_html'] = $tags;
filter_format_save($format);
}
/**
* Create a new storage field to use for description truncation.
*/
function islandora_solr_metadata_update_7104() {
db_add_field('islandora_solr_metadata_associations', 'description_data', array(
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
'description' => 'A serialized array of name value pairs that store extra description field settings.',
));
}
/**
* Implements hook_install().
*/
function islandora_solr_metadata_install() {
$t = get_t();
$format = filter_format_load('filtered_html');
$format->format = 'islandora_solr_metadata_filtered_html';
$format->name = $t('Islandora Solr Metadata Filtered HTML');
$format->filters = filter_list_format('filtered_html');
foreach ($format->filters as $key => $filter) {
$format->filters[$key] = (array) $filter;
}
$to_exist = array(
'<a>',
'<span>',
);
$tags = $format->filters['filter_html']['settings']['allowed_html'];
foreach ($to_exist as $add) {
if (strpos($tags, $add) === FALSE) {
$tags .= " $add";
}
}
$format->filters['filter_html']['settings']['allowed_html'] = $tags;
filter_format_save($format);
}