-
Notifications
You must be signed in to change notification settings - Fork 0
/
dkan.install
896 lines (775 loc) · 25.5 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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
<?php
/**
* @file
* Install functions and update hooks for DKAN profile.
*/
use Dkan\Datastore\Manager\Factory;
use Dkan\Datastore\Resource;
use Dkan\Datastore\Manager\ManagerInterface;
use Dkan\Datastore\LockableDrupalVariables;
/**
* 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) {
require_once('dkan.profile');
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');
}
/**
* Remove deprecated stories view.
*/
function dkan_update_7028() {
// Check that the view exists.
if ($view = views_get_view('stories')) {
// Delete the view.
views_delete_view($view);
}
}
/**
* Change field_harvest_source_modified from a datetime to text field. See #2612.
*/
function dkan_update_7029() {
features_revert_module('dkan_dataset_content_types');
// Add format column to harvest_source_modified tables.
$tables = array(
'field_data_field_harvest_source_modified',
'field_revision_field_harvest_source_modified'
);
$spec = array(
'type' => 'varchar',
'length' => 100,
'not null' => FALSE,
'default' => '',
);
foreach ($tables as $table) {
db_add_field($table, 'field_harvest_source_modified_format', $spec);
db_change_field($table, 'field_harvest_source_modified_value', 'field_harvest_source_modified_value', $spec);
// Convert dates to strings.
$result = db_select($table, 'm')
->fields('m', array(
'field_harvest_source_modified_value',
'revision_id'
))
->execute()
->fetchAll();
foreach($result as $row) {
$string =substr($row->field_harvest_source_modified_value, 0, 10);
db_update($table)
->fields(array(
'field_harvest_source_modified_value' => $string
))
->condition('revision_id', $row->revision_id)
->execute();
}
}
// Fetch the current harvest_source_modified field_config, then update it.
$field_config = db_select('field_config', 'f')
->fields('f', array('data'))
->condition('field_name', 'field_harvest_source_modified')
->execute()
->fetchCol();
$data = unserialize($field_config[0]);
$data['indexes']['format'][0] = 'format';
$data['settings'] = array();
$data['settings'] = array('max_length' => '255');
$data['foreign keys']['format']['table'] = 'filter_format';
$data['foreign keys']['format']['columns']['format'] = 'format';
$data = serialize($data);
// Update with new field configuration.
db_update('field_config')
->fields(array(
'data' => $data,
'type' => 'text',
'module' => 'text'
))
->condition('field_name', 'field_harvest_source_modified')
->execute();
// Fetch the current harvest_source_modified field_config_instance, then update it.
$field_config = db_select('field_config_instance', 'f')
->fields('f', array('data'))
->condition('field_name', 'field_harvest_source_modified')
->execute()
->fetchCol();
$data = unserialize($field_config[0]);
$data['default_value'] = NULL;
$data['settings'] = array();
$data['settings']= array('text_processing' => 0, 'user_register_form' => FALSE);
$data['widget']['module'] = 'text';
$data['widget']['settings'] = array();
$data['widget']['settings'] = array('size' => 60);
$data['widget']['type'] = 'text_textfield';
$data = serialize($data);
// Update with new field configuration.
db_update('field_config_instance')
->fields(array(
'data' => $data,
))
->condition('field_name', 'field_harvest_source_modified')
->execute();
}
/**
* Update field_frequency_value to store ISO code rather than integers.
*/
function dkan_update_7030() {
// Change frequency field_config from list_int to list_text.
$field_config = db_select('field_config', 'f')
->fields('f', array('data'))
->condition('field_name', 'field_frequency')
->execute()
->fetchCol();
$data = unserialize($field_config[0]);
$data['settings']['allowed_values'] = array();
$data['settings']['allowed_values_function'] = 'dkan_dataset_content_types_iso_frecuency_map';
$data = serialize($data);
db_update('field_config')
->fields(array(
'type' => 'list_text',
'data' => $data,
))
->condition('field_name', 'field_frequency')
->execute();
// Change field_frequency_value type from int to varchar.
$tables = array(
'field_data_field_frequency',
'field_revision_field_frequency'
);
$spec = array(
'type' => 'varchar',
'length' => 15,
'not null' => FALSE,
'default' => '',
);
foreach ($tables as $table) {
db_change_field($table, 'field_frequency_value', 'field_frequency_value', $spec);
// Convert integers to strings.
$result = db_select($table, 'm')
->fields('m', array(
'field_frequency_value',
'revision_id'
))
->execute()
->fetchAll();
foreach($result as $row) {
// Convert integer values to ISO 8601 value.
switch ($row->field_frequency_value) {
case '0':
$val = 'R/P1D';
break;
case '1':
$val = 'R/P1W';
break;
case '2':
$val = 'R/P1M';
break;
case '3':
$val = 'R/P1Y';
break;
case '4':
$val = 'R/PT1S';
break;
case '5':
$val = 'irregular';
break;
case '6':
$val = 'R/P10Y';
break;
case '7':
$val = 'R/P4Y';
break;
case '8':
$val = 'R/P2M';
break;
case '9':
$val = 'R/P3.5D';
break;
case '10':
$val = 'R/P2W';
break;
case '11':
$val = 'R/P6M';
break;
case '12':
$val = 'R/P2Y';
break;
case '13':
$val = 'R/P3Y';
break;
case '14':
$val = 'R/P0.33W';
break;
case '15':
$val = 'R/P0.33M';
break;
case '16':
$val = 'R/P3M';
break;
case '17':
$val = 'R/P4M';
break;
case '18':
$val = 'R/P0.5M';
break;
default:
$val = '';
break;
}
db_update($table)
->fields(array(
'field_frequency_value' => $val,
))
->condition('revision_id', $row->revision_id)
->execute();
}
}
}
/**
* Enable the simple import module.
*/
function dkan_update_7031() {
module_enable(array('dkan_datastore_simple_import'));
}
function _dkan_remove_prefix($prefix, $string) {
if (substr($string, 0, strlen($prefix)) == $prefix) {
$string = substr($string, strlen($prefix));
}
return $string;
}
/**
* Rename feeds_datastore tables.
*/
function dkan_update_7032() {
global $databases;
$prefix = "";
if (isset($databases['default']['default']['prefix'])) {
$prefix = $databases['default']['default']['prefix'];
}
// I have seen both of these patterns used, I am not sure if it is related
// to a version of feeds or not, so we are checking both.
$possibilities = [
"%feeds_datastore_dkan_%",
"%feeds_datastore_%",
];
foreach ($possibilities as $string) {
foreach (db_find_tables($string) as $table_name) {
// db_find_tables returns full table names with a prefix if
// configured. The rest of db functions will work without
// explicitely setting the prefix. We need to remove
// the prefix for db_rename_table to work correctly.
$table_name = _dkan_remove_prefix($prefix, $table_name);
$clean = str_replace("%", "", $string);
$new_table_name = str_replace("{$clean}file", "dkan_datastore", $table_name);
$new_table_name = str_replace("{$clean}link", "dkan_datastore", $new_table_name);
db_rename_table($table_name, $new_table_name);
}
}
}
/**
* Generate basic datastore configuration.
*/
function dkan_update_7033() {
global $databases;
$prefix = "";
if (isset($databases['default']['default']['prefix'])) {
$prefix = $databases['default']['default']['prefix'];
}
foreach (db_find_tables("%dkan_datastore%") as $table_name) {
$table_name = _dkan_remove_prefix($prefix, $table_name);
$nid = str_replace("dkan_datastore_", "", $table_name);
try {
$resource = Resource::createFromDrupalNodeNid($nid);
/* @var $manager \Dkan\Datastore\Manager\SimpleImport\SimpleImport */
$manager = (new Factory($resource))->get();
$manager->saveState();
}
catch( \Exception $e) {}
}
}
/**
* Update the datastore configuration.
*/
function dkan_update_7034() {
$storage = new LockableDrupalVariables("dkan_datastore");
$bin = $storage->borrowBin();
foreach ($bin as $nid => $state) {
$bin[$nid]['data_import'] = ManagerInterface::DATA_IMPORT_DONE;
$bin[$nid]['storage'] = ManagerInterface::STORAGE_INITIALIZED;
}
$storage->returnBin($bin);
}
/**
* Disable feeds modules.
*/
function dkan_update_7035() {
# Deprecating feeds modules as they are no longer used in dkan_datastore.
if( module_exists('feeds')) {
module_disable(array('feeds', 'feeds_field_fetcher', 'feeds_flatstore_processor'));
drupal_uninstall_modules(array('feeds', 'feeds_field_fetcher', 'feeds_flatstore_processor'));
}
}
/**
* Enable fast token browser, included with new version of open_data_schema_map.
*/
function dkan_update_7036() {
module_enable(['fast_token_browser']);
}
/**
* Disable/uninstall admin_views.
*/
function dkan_update_7037() {
if (module_exists('admin_views')) {
module_disable(array('admin_views'));
drupal_uninstall_modules(array('admin_views'));
db_delete('cache_views')
->condition('cid', '%administration%', 'LIKE')
->execute();
db_delete('system')
->condition('name', 'admin_views')
->execute();
db_delete('system')
->condition('name', 'admin_views_test')
->execute();
$default = variable_get('views_defaults');
unset($default['admin_views_file']);
unset($default['admin_views_node']);
variable_set('views_defaults', $default);
}
}
/**
* Enable admin_views.
*/
function dkan_update_7038() {
module_enable(['admin_views']);
}
/**
* Clean up db.
*
* Remove deprecated roles and permissions module.
*/
function dkan_update_7039() {
if (!module_exists('dkan_sitewide_roles_perms')) {
db_delete('system')
->condition('name', 'dkan_sitewide_roles_perms')
->condition('type', 'module')
->execute();
}
}
/**
* Enable new search feature
*/
function dkan_update_7040() {
// check that the core modules are still enabled
if (module_exists('dkan_sitewide_search_db') && module_exists('dkan_sitewide_panels')) {
module_enable(array('dkan_dataset_search'));
}
}
/**
* User newer jquery
*/
function dkan_update_7041() {
variable_set('jquery_update_jquery_version', '1.12');
variable_set('jquery_update_jquery_migrate_enable', '1');
}