forked from GetDKAN/dkan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdkan.install
469 lines (416 loc) · 15 KB
/
dkan.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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
<?php
/**
* @file
* Install functions and update hooks for DKAN profile.
*/
/**
* Reverts dkan_sitewide to add Markdown filter. Sets up roleassign feature.
*/
function dkan_update_7001() {
module_load_include("profile", "dkan");
dkan_bueditor_markdown_install();
}
/**
* Rename a field.
*
* Addapted from field_rename_rename_fields() in 'Field Rename' module.
*
* @param string $old_field_name
* The old name of the field.
* @param string $new_field_name
* The new name of the field.
*/
function dkan_rename_field($old_field_name, $new_field_name) {
$messages = array();
// Read field data.
$old_field = field_read_field($old_field_name);
if (empty($old_field)) {
$messages[] = t('The field %old_field_name does not exist so it cannot be renamed.', array('%old_field_name' => $old_field_name));
return $messages;
}
try {
// Update {field_config}.
db_update('field_config')
->fields(array('field_name' => $new_field_name))
->condition('id', $old_field['id'])
->execute();
// Update {field_config_instance}.
db_update('field_config_instance')
->fields(array('field_name' => $new_field_name))
->condition('field_id', $old_field['id'])
->execute();
// The tables that need updating in the form 'old_name' => 'new_name'.
$tables = array(
'field_data_' . $old_field_name => 'field_data_' . $new_field_name,
'field_revision_' . $old_field_name => 'field_revision_' . $new_field_name,
);
// Iterate through tables to be redefined and renamed.
foreach ($tables as $old_table => $new_table) {
// Iterate through the field's columns. For example, a 'text' field will
// have columns 'value' and 'format'.
foreach ($old_field['columns'] as $column_name => $column_definition) {
// Column names are in the format {field_name}_{column_name}.
$old_column_name = $old_field_name . '_' . $column_name;
$new_column_name = $new_field_name . '_' . $column_name;
// If there is an index for the field, drop and then re-add it.
$has_index = isset($old_field['indexes'][$column_name]) && ($old_field['indexes'][$column_name] == array($column_name));
if ($has_index) {
db_drop_index($old_table, $old_column_name);
}
// Rename the column.
db_change_field($old_table, $old_column_name, $new_column_name, $column_definition);
if ($has_index) {
db_drop_index($old_table, $new_column_name);
db_add_index($old_table, $new_column_name, array($new_column_name));
}
}
// The new table may exist e.g. due to having been included in a feature
// that was reverted prior to this update being run. If so, we need to
// drop the new table so that the old one can be renamed.
if (db_table_exists($new_table)) {
db_drop_table($new_table);
}
// Rename the table.
db_rename_table($old_table, $new_table);
}
}
catch (Exception $e) {
$messages[] = t('The field %old_field_name could not be renamed because there was an error: %error.',
array('%old_field_name' => $old_field_name, '%error' => $e->getMessage()));
}
cache_clear_all('*', 'cache_field', TRUE);
return $messages;
}
/**
* Update the default jquery library to 1.10.
*/
function dkan_update_7002() {
if (version_compare(variable_get('jquery_update_jquery_version'), '1.10', '<')) {
variable_set('jquery_update_jquery_version', '1.10');
}
}
/**
* Disable the dkan_default_content module.
*/
function dkan_update_7005() {
db_update('system')
->fields(array('status' => '0'))
->condition('name', 'dkan_default_content')
->execute();
}
/**
* We need to revert field instances.
*
* This is required for the next update in another case
* we have problem with new fields added on version 12.
*/
function dkan_update_7006() {
module_enable(array('field_hidden'));
features_revert(array('dkan_datastore' => array('field_base', 'field_instance')));
}
/**
* Resource group field.
*
* Groups cannot be edited manually on resources anymore. Group affiliation
* will be inherited from parent datasets. This update hook was added to be sure
* that all resources that do not have groups assigned are synchronized and
* updated with the groups from the parent datasets.
*/
function dkan_update_7007(&$sandbox) {
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['max'] = db_query("SELECT COUNT(DISTINCT fdr.field_dataset_ref_target_id) FROM {node} n LEFT JOIN {field_data_field_dataset_ref} fdr ON fdr.entity_id=n.nid LEFT JOIN {og_membership} og ON n.nid=og.etid WHERE n.type='resource' AND og.etid IS NULL AND fdr.field_dataset_ref_target_id IN (SELECT etid FROM {og_membership} WHERE etid IN (SELECT field_dataset_ref_target_id FROM {field_data_field_dataset_ref}))")->fetchField();
}
// Get all resources without group but the parent dataset has groups.
$result = db_query("SELECT DISTINCT fdr.field_dataset_ref_target_id FROM {node} n LEFT JOIN {field_data_field_dataset_ref} fdr ON fdr.entity_id=n.nid LEFT JOIN {og_membership} og ON n.nid=og.etid WHERE n.type='resource' AND og.etid IS NULL AND fdr.field_dataset_ref_target_id IN (SELECT etid FROM {og_membership} WHERE etid IN (SELECT field_dataset_ref_target_id FROM {field_data_field_dataset_ref})) LIMIT 0,10");
foreach ($result as $item) {
// Simulate a empty original.
// The 'dkan_dataset_sync_groups' function synchronizes
// the groups only when a change on the dataset is detected.
$original = new stdClass();
$original->type = 'dataset';
$original->og_group_ref = array();
$dataset = node_load($item->field_dataset_ref_target_id);
$dataset->original = $original;
dkan_dataset_sync_groups($dataset);
$sandbox['progress']++;
}
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
return t('All resources without group were updated.');
}
/**
* Point source menu to the command menu center in dkan workflow roles.
*/
function dkan_update_7008() {
if (module_exists('dkan_workflow')) {
dkan_workflow_admin_menu_source();
}
}
/**
* Flush client site colorizer file to grab new updates.
*/
function dkan_update_7009() {
$theme = $GLOBALS['theme'];
$instance = $theme;
variable_del('colorizer_' . $instance . '_files');
colorizer_clearcache();
cache_clear_all();
}
/**
* Disable/uninstall deprecated dkan_dataset_api, enable open_data_schema_map.
*/
function dkan_update_7010() {
if (module_exists('dkan_dataset_api')) {
module_disable(array('dkan_dataset_api'));
drupal_uninstall_modules(array('dkan_dataset_api'));
module_enable(array('open_data_schema_map'));
}
}
/**
* Update copyright information.
*/
function dkan_update_7011() {
$settings = variable_get('theme_nuboot_radix_settings', array());
if ($settings['copyright']['value'] == 'Powered by <a href="http://nucivic.com/dkan">DKAN</a>, a project of <a href="http://nucivic.com">NuCivic</a>') {
$settings['copyright']['value'] = t('Powered by <a href="http://getdkan.com/">DKAN</a>, a project of <a href="http://granicus.com">Granicus</a>');
variable_set('theme_nuboot_radix_settings', $settings);
}
}
/**
* Clean up db on upgrade to 7.x-1.13.
*
* Deprecated modules: Conditional Fields, Entity RDF, RDF UI, RDF Extensions.
*/
function dkan_update_7012() {
if (!module_exists('conditional_fields')) {
db_delete('system')
->condition('name', 'conditional_fields')
->condition('type', 'module')
->execute();
db_drop_table('conditional_fields');
}
if (!module_exists('entity_rdf')) {
db_delete('system')
->condition('name', 'entity_rdf')
->condition('type', 'module')
->execute();
}
if (!module_exists('rdfui')) {
db_delete('system')
->condition('name', 'rdfui')
->condition('type', 'module')
->execute();
}
if (!module_exists('rdfx')) {
db_delete('system')
->condition('name', 'rdfx')
->condition('type', 'module')
->execute();
db_drop_table('rdfx_namespaces');
db_drop_table('rdfx_term_details');
db_drop_table('rdfx_term_domains');
db_drop_table('rdfx_term_inverses');
db_drop_table('rdfx_term_ranges');
db_drop_table('rdfx_term_superclasses');
db_drop_table('rdfx_term_superproperties');
db_drop_table('rdfx_term_types');
db_drop_table('rdfx_terms');
db_drop_table('rdfx_vocabulary_details');
db_drop_table('rdfx_vocabulary_graphs');
}
}
/**
* Remove deprecated test and theme directories.
*/
function dkan_update_7013() {
$deprecated = array(
'profiles/dkan/modules/dkan/dkan_dataset/fonts',
'profiles/dkan/modules/dkan/dkan_dataset/tests',
'profiles/dkan/modules/dkan/dkan_datastore/tests',
'profiles/dkan/modules/dkan/dkan_datastore/modules/dkan_datastore_api/tests',
'profiles/dkan/modules/dkan/dkan_datastore/modules/dkan_datastore_fast_import/test',
'profiles/dkan/modules/dkan/dkan_workflow/test',
'profiles/dkan/themes/contrib/nuboot_radix',
'profiles/dkan/themes/contrib/omega',
);
foreach ($deprecated as $dir) {
if (is_dir($dir)) {
drupal_rmdir($dir);
}
}
}
/**
* Drop the 'field_modified_source_date' field.
*/
function dkan_update_7014() {
// Mark the field for deletion.
field_delete_field('field_modified_source_date');
// Run the batch process to actually delete the field.
$batch_size = 1;
field_purge_batch($batch_size);
}
/**
* Update the default jquery library to 1.10 (again).
*/
function dkan_update_7015() {
if (version_compare(variable_get('jquery_update_jquery_version'), '1.10', '<')) {
variable_set('jquery_update_jquery_version', '1.10');
}
}
/**
* Add data dictionary textarea id to bueditor excludes list.
*/
function dkan_update_7016() {
db_update('bueditor_editors')
->fields(array(
'excludes' => 'edit-log
edit-menu-description
*data-dictionary*',
))
->condition('eid', '5')
->execute();
}
/**
* Update chosen_jquery_selector to avoid misuse.
*/
function dkan_update_7017() {
variable_set('chosen_jquery_selector',
'.page-node select:not([class*="delta-order"], [name*="workbench_moderation"], [class*="filter-list"], [id*="delimiter"],[name*="sort_by"],[name*="sort_order"])');
}
/**
* Update language field values to use dashes rather than underscores.
*/
function dkan_update_7018() {
db_update('field_data_field_language')
->expression('field_language_value', 'replace(field_language_value, :underscore, :dash)', array(':underscore' => '_', ':dash' => '-'))
->execute();
db_update('field_revision_field_language')
->expression('field_language_value', 'replace(field_language_value, :underscore, :dash)', array(':underscore' => '_', ':dash' => '-'))
->execute();
}
/**
* Remove old variables from dkan_dataset_api.
*/
function dkan_update_7019() {
variable_del('dkan_catalog_desc');
variable_del('dkan_catalog_contact');
variable_del('dkan_catalog_mbox');
variable_del('dkan_dataset_api_site_read');
variable_del('dkan_dataset_api_data_json');
variable_del('dkan_dataset_api_revision_list');
variable_del('dkan_dataset_api_package_list');
variable_del('dkan_dataset_api_current_package_list_with_resources');
variable_del('dkan_dataset_api_package_show');
variable_del('dkan_dataset_api_resource_show');
variable_del('dkan_dataset_api_group_package_show');
variable_del('dkan_dataset_api_package_revision_list');
variable_del('dkan_dataset_api_group_list');
}
/**
* Update chosen_jquery_selector to avoid misuse.
*/
function dkan_update_7020() {
// REF #1936, #1890.
variable_set('chosen_jquery_selector',
'.page-node select:not([class*="delta-order"], [name*="workbench_moderation"], [class*="filter-list"], [id*="delimiter"],[name*="sort_by"],[name*="sort_order"], [id*="lines-terminated-by"])');
}
/**
* Add data dictionary textarea id to bueditor excludes list.
*
* This is similar to 'dkan_update_7016' but loading the ID from the DB first.
*/
function dkan_update_7021() {
$eid = db_select("bueditor_editors", "bue")
->fields("bue", array("eid"))
->condition("name", "Markdowneditor")
->execute()
->fetchField();
db_update('bueditor_editors')
->fields(array(
'excludes' => 'edit-log
edit-menu-description
*data-dictionary*',
))
->condition('eid', $eid)
->execute();
}
/**
* Update chosen_jquery_selector to include language selectors.
*/
function dkan_update_7022() {
// REF #1936, #1890.
variable_set('chosen_jquery_selector',
'.page-node select:not([class*="delta-order"], [name*="workbench_moderation"], [class*="filter-list"], [id*="delimiter"],[name*="sort_by"],[name*="sort_order"], [id*="lines-terminated-by"], [id*="lang-dropdown-select-language"])');
}
/**
* Remove deprecated modules from the db: menu_token and remote_file_source.
*/
function dkan_update_7023() {
if (!module_exists('menu_token')) {
db_delete('system')
->condition('name', 'menu_token')
->condition('type', 'module')
->execute();
db_drop_table('menu_token');
}
if (!module_exists('remote_file_source')) {
db_delete('system')
->condition('name', 'remote_file_source')
->condition('type', 'module')
->execute();
}
}
/**
* Update default variables.
*/
function dkan_update_7024(&$context) {
dkan_misc_variables_set($context);
}
/**
* Update copyright information.
*/
function dkan_update_7025() {
$settings = variable_get('theme_nuboot_radix_settings', array());
if ($settings['copyright']['value'] == 'Powered by <a href="http://getdkan.com/">DKAN</a>, a project of <a href="http://granicus.com">Granicus</a>') {
$settings['copyright']['value'] = t('Powered by <a href="https://getdkan.org/">DKAN</a>');
variable_set('theme_nuboot_radix_settings', $settings);
}
}
/**
* Revert content types dataset to revert og_group_ref on resources.
*/
function dkan_update_7026() {
features_revert(array('dkan_dataset_content_types' => array('field_base', 'field_instance')));
}
/**
* Make sure revised settings for harvest dates are applied. See #2495.
*/
function dkan_update_7027() {
features_revert_module('dkan_dataset_content_types');
// Get a list of harvested datasets.
$harvested_nids = db_select('field_data_field_harvest_source_ref', 'hsr')
->fields('hsr', array('entity_id'))
->execute()
->fetchCol();
// Get a list of all datasets.
$dataset_ids = db_select('node', 'n')
->fields('n', array('nid'))
->condition('type', 'dataset')
->execute()
->fetchCol();
// Process all datasets to clear the harvest dates from non-harvested entries.
$count = 0;
foreach ($dataset_ids as $nid) {
// Delete the entries for non-harvested datasets.
if (!in_array($nid, $harvested_nids)) {
db_delete('field_data_field_harvest_source_modified')
->condition('entity_id', $nid)
->execute();
db_delete('field_data_field_harvest_source_issued')
->condition('entity_id', $nid)
->execute();
}
$count = $count + 1;
}
drupal_set_message(t('Removed harvest date values from @var non-harvested datasets.', array('@var' => $count)), 'status');
}