-
Notifications
You must be signed in to change notification settings - Fork 2
/
tripal_file.install
executable file
·918 lines (847 loc) · 23.6 KB
/
tripal_file.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
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
<?php
/**
* @file
*
* Installation of the file module
*/
/**
* Implements hook_requirements().
*/
function tripal_file_requirements($phase) {
$requirements = [];
if ($phase == 'install') {
if (!module_exists('tripal_core') and !module_exists('tripal')) {
$requirements['tripal_file'] = [
'title' => "tripal_file",
'value' => "ERROR: You must have Tripal v2 or v3 installed to use this module.",
'severity' => REQUIREMENT_ERROR,
];
}
}
return $requirements;
}
/**
* Implements hook_install().
*
* Performs actions when the modules is first installed.
*
* @ingroup tripal_file
*/
function tripal_file_install() {
// Add the custom tables needed to associate Chado content with files.
tripal_file_add_file_table();
tripal_file_add_license_table();
tripal_file_add_file_contact_table();
tripal_file_add_fileloc_table();
tripal_file_add_fileprop_table();
tripal_file_add_file_relationship_table();
tripal_file_add_file_license_table();
tripal_file_add_file_pub_table();
tripal_file_add_linker_tables();
// Add the terms and content types.
tripal_file_add_terms();
tripal_file_add_ctypes();
tripal_file_add_EDAM_obo();
// Associate terms with the linker tables.
tripal_file_add_linker_tables_terms();
tripal_file_add_default_licenses();
}
/**
*
*/
function tripal_file_add_EDAM_obo() {
// Add the EDAM ontology
$obo_id = tripal_insert_obo('EDAM', 'http://edamontology.org/EDAM.obo');
drupal_set_message('NOTICE: Added the EDAM ontology. Please navigate to Tripal >> Data Loaders >> Chado Vocabularies >> OBO Vocabulary Loader and submit a job to import the EDAM vocabulary.');
}
/**
*
*/
function tripal_file_add_terms() {
// The SIO cv does not need to be added because it is
// automatically added by the base Tripal setup.
//
// Content type terms
//
$term = chado_insert_cvterm([
'id' => 'SIO:000396',
'name' => 'file',
'cv_name' => 'SIO',
'definition' => 'A file is an information-bearing object that contains a physical embodiment of some information using a particular character encoding',
], ['update_existing' => false]);
chado_associate_semweb_term(NULL, 'file_id', $term);
$term = chado_insert_cvterm([
'id' => 'schema:license',
'name' => 'license',
'cv_name' => 'schema',
'definition' => 'A license document that applies to this content, typically indicated by URL.',
], ['update_existing' => false]);
chado_associate_semweb_term(NULL, 'license_id', $term);
//
// Terms for the File table.
//
$term = chado_get_cvterm(['id' => 'schema:name']);
chado_associate_semweb_term('file', 'name', $term);
$term = chado_get_cvterm(['id' => 'schema:description']);
chado_associate_semweb_term('file', 'description', $term);
$term = chado_insert_cvterm([
'id' => 'format:1915',
'name' => 'Format',
'cv_name' => 'EDAM',
'definition' => 'A defined way or layout of representing and structuring data in a computer file, blob, string, message, or elsewhere.',
], ['update_existing' => false]);
chado_associate_semweb_term('file', 'type_id', $term);
//
// Terms for the file_contact table
//
$term = chado_get_cvterm(['id' => 'local:contact']);
chado_associate_semweb_term('file_contact', 'contact_id', $term);
//
// Terms for the fileloc table
//
$term = chado_get_cvterm(['id' => 'data:1047']);
chado_associate_semweb_term('fileloc', 'uri', $term);
$term = chado_get_cvterm(['id' => 'OBCS:0000117']);
chado_associate_semweb_term('fileloc', 'rank', $term);
$term = chado_get_cvterm(['id' => 'data:2190']);
chado_associate_semweb_term('fileloc', 'md5checksum', $term);
$term = chado_insert_cvterm([
'id' => 'schema:fileSize',
'name' => 'fileSize',
'cv_name' => 'schema',
'definition' => 'Size of the application / package (e.g. 18MB). In the absence of a unit (MB, KB etc.), KB will be assumed.',
], ['update_existing' => false]);
chado_associate_semweb_term('fileloc', 'size', $term);
$term = chado_insert_cvterm([
'id' => 'data:1050',
'name' => 'File name',
'cv_name' => 'EDAM',
'definition' => 'The name (or part of a name) of a file (of any type).',
], ['update_existing' => false]);
chado_associate_semweb_term('fileloc', 'filename', $term);
//
// Terms for the fileprop table
//
$term = chado_get_cvterm(['id' => 'OBCS:0000117']);
chado_associate_semweb_term('fileprop', 'rank', $term);
$term = chado_get_cvterm(['id' => 'NCIT:C25712']);
chado_associate_semweb_term('fileprop', 'value', $term);
$term = chado_get_cvterm(['id' => 'schema:additionalType']);
chado_associate_semweb_term('fileprop', 'type_id', $term);
//
// Terms for the license table
//
$term = chado_get_cvterm(['id' => 'schema:name']);
chado_associate_semweb_term('license', 'name', $term);
$term = chado_get_cvterm(['id' => 'data:1047']);
chado_associate_semweb_term('license', 'uri', $term);
$term = chado_insert_cvterm([
'id' => 'schema:disambiguatingDescription',
'name' => 'disambiguatingDescription',
'cv_name' => 'schema',
'definition' => 'A sub property of description. A short description of the item used to disambiguate from other, similar items. Information from other properties (in particular, name) may be necessary for the description to be useful for disambiguation.',
], ['update_existing' => false]);
chado_associate_semweb_term('license', 'summary', $term);
//
// Terms for the file_license table
//
// No terms needed, just linking fields.
//
// Field types
//
$term = chado_insert_cvterm([
'id' => 'schema:itemLocation',
'name' => 'itemLocation',
'cv_name' => 'schema',
'definition' => 'Current location of the item.',
], ['update_existing' => false]);
}
/**
* Adds Tripal v3 content types.
*/
function tripal_file_add_ctypes() {
// Add the File content type
$bundle = tripal_load_bundle_entity(['accession' => 'SIO:000396']);
if (!$bundle) {
$args = [
'vocabulary' => 'SIO',
'accession' => '000396',
'term_name' => 'file',
'label' => "File",
'storage_args' => [
'data_table' => 'file',
],
'category' => 'Other',
];
if (!tripal_create_bundle($args, $job)) {
$msg = t('Error encountered creating !type Content Type.', ['!type' => $args['term_name']]);
throw new Exception($msg);
}
}
// Add the License content type
$bundle = tripal_load_bundle_entity(['accession' => 'schema:license']);
if (!$bundle) {
$args = [
'vocabulary' => 'schema',
'accession' => 'license',
'term_name' => 'license',
'label' => "License",
'storage_args' => [
'data_table' => 'license',
],
'category' => 'Other',
];
if (!tripal_create_bundle($args, $job)) {
$msg = t('Error encountered creating !type Content Type.', ['!type' => $args['term_name']]);
throw new Exception($msg);
}
}
}
/**
* Adds the 'file' custom table to Chado.
*
* @ingroup tripal_file
*/
function tripal_file_add_file_table() {
$schema = [
'table' => 'file',
'fields' => [
'file_id' => [
'size' => 'big',
'type' => 'serial',
'not null' => TRUE,
],
'name' => [
'type' => 'text',
'not null' => TRUE,
],
'type_id' => [
'type' => 'int',
'not null' => TRUE
],
'description' => [
'type' => 'text',
],
],
'primary key' => ['file_id'],
'unique keys' => [
'file_c1' => ['name'],
],
'indexes' => [
'file_idx1' => ['name'],
'file_idx2' => ['type_id'],
],
'foreign keys' => [
'cvterm' => [
'table' => 'cvterm',
'columns' => [
'type_id' => 'cvterm_id',
],
],
],
];
chado_create_custom_table('file', $schema, TRUE, NULL, FALSE);
}
/**
*
*/
function tripal_file_add_file_contact_table(){
$schema = [
'table' => 'file_contact',
'fields' => [
'file_contact_id' => [
'size' => 'big',
'type' => 'serial',
'not null' => TRUE
],
'file_id' => [
'type' => 'int',
'not null' => TRUE
],
'contact_id' => [
'type' => 'int'
],
],
'primary key' => ['file_contact_id'],
'unique keys' => [
'file_contact_c1' => ['file_id', 'contact_id'],
],
'indexes' => [
'file_contact_idx1' => ['file_id'],
'file_contact_idx2' => ['contact_id'],
],
'foreign keys' => [
'file' => [
'table' => 'file',
'columns' => [
'file_id' => 'file_id',
],
],
'contact' => [
'table' => 'contact',
'columns' => [
'contact_id' => 'contact_id',
],
],
],
];
chado_create_custom_table('file_contact', $schema, TRUE, NULL, FALSE);
}
/**
*
*/
function tripal_file_add_file_pub_table() {
$schema = [
'table' => 'file_pub',
'fields' => [
'file_pub_id' => [
'size' => 'big',
'type' => 'serial',
'not null' => TRUE,
],
'file_id' => [
'size' => 'big',
'type' => 'int',
'not null' => TRUE,
],
'pub_id' => [
'size' => 'big',
'type' => 'int',
'not null' => TRUE,
],
],
'primary key' => [
0 => 'file_pub_id',
],
'unique keys' => [
'file_pub_c1' => [
0 => 'file_id',
1 => 'pub_id',
],
],
'indexes' => [
'file_pub_idx1' => [
0 => 'file_id',
],
'file_pub_idx2' => [
0 => 'pub_id',
],
],
'foreign keys' => [
'pub' => [
'table' => 'pub',
'columns' => [
'pub_id' => 'pub_id',
],
],
'file' => [
'table' => 'file',
'columns' => [
'file_id' => 'file_id',
],
],
],
];
chado_create_custom_table('file_pub', $schema, TRUE, NULL, FALSE);
}
/**
*
*/
function tripal_file_add_fileloc_table(){
$schema = [
'table' => 'fileloc',
'fields' => [
'fileloc_id' => [
'size' => 'big',
'type' => 'serial',
'not null' => TRUE
],
'file_id' => [
'type' => 'int',
'not null' => TRUE,
],
'uri' => [
'type' => 'text',
'not null' => TRUE,
'description' => t('Can be one of the following 1) A relative URL which can be concatenated to the http://[domain]. 2) A Drupal scheme (e.g. public://[path]) 3) A full URL to a remote site.')
],
'rank' => [
'type' => 'int',
'not null' => TRUE,
'default' => 0
],
'md5checksum' => [
'size' => 'normal',
'type' => 'char',
'length' => '32',
'not null' => FALSE
],
'size' => [
'type' => 'varchar',
'length' => 1024,
'not null' => FALSE
],
'filename' => [
'type' => 'text',
'not null' => FALSE,
'description' => t('The short name of the uri as displayed to the user.'),
],
],
'primary key' => ['fileloc_id'],
'unique keys' => [
'fileloc_c1' => ['file_id', 'uri'],
],
'indexes' => [
'fileloc_idx1' => ['file_id'],
],
'foreign keys' => [
'file' => [
'table' => 'file',
'columns' => [
'file_id' => 'file_id',
],
],
],
];
chado_create_custom_table('fileloc', $schema, TRUE, NULL, FALSE);
}
/**
*
*/
function tripal_file_add_fileprop_table(){
$schema = [
'table' => 'fileprop',
'fields' => [
'fileprop_id' => [
'type' => 'serial',
'not null' => TRUE
],
'file_id' => [
'type' => 'int',
'not null' => TRUE
],
'type_id' => [
'type' => 'int',
'not null' => TRUE
],
'value' => [
'type' => 'text'
],
'rank' => [
'type' => 'int',
'not null' => TRUE,
'default' => 0
],
],
'primary key' => ['fileprop_id'],
'unique keys' => [
'fileprop_c1' => ['file_id', 'type_id', 'rank'],
],
'indexes' => [
'fileprop_idx1' => ['file_id'],
'fileprop_idx2' => ['type_id'],
],
'foreign keys' => [
'file' => [
'table' => 'file',
'columns' => [
'file_id' => 'file_id',
],
],
'cvterm' => [
'table' => 'cvterm',
'columns' => [
'type_id' => 'cvterm_id',
],
],
],
];
chado_create_custom_table('fileprop', $schema, TRUE, NULL, FALSE);
}
/**
*
*/
function tripal_file_add_file_relationship_table(){
$schema = [
'table' => 'file_relationship',
'fields' => [
'file_relationship_id' => [
'type' => 'serial',
'not null' => TRUE
],
'subject_id' => [
'type' => 'int',
'not null' => TRUE
],
'object_id' => [
'type' => 'int',
'not null' => TRUE
],
'type_id' => [
'type' => 'int',
'not null' => TRUE
],
],
'primary key' => ['file_relationship_id'],
'unique keys' => [
'file_relationship_c1' => ['subject_id', 'object_id', 'type_id'],
],
'indexes' => [
'file_relationship_idx1' => ['subject_id'],
'file_relationship_idx2' => ['object_id'],
'file_relationship_idx3' => ['type_id'],
],
'foreign keys' => [
'file' => [
'table' => 'file',
'columns' => [
'subject_id' => 'file_id',
'object_id' => 'file_id',
],
],
'cvterm' => [
'table' => 'cvterm',
'columns' => [
'type_id' => 'cvterm_id',
],
],
],
];
chado_create_custom_table('file_relationship', $schema, TRUE, NULL, FALSE);
}
/**
*
*/
function tripal_file_add_license_table(){
$schema = [
'table' => 'license',
'fields' => [
'license_id' => [
'type' => 'serial',
'not null' => TRUE
],
'name' => [
'type' => 'varchar',
'length' => 1024,
'not null' => TRUE
],
'summary' => [
'type' => 'text',
],
'uri' => [
'type' => 'text',
],
],
'primary key' => ['license_id'],
'unique keys' => [
'license_c1' => ['name'],
'license_c2' => ['uri'],
],
'indexes' => [
'license_idx1' => ['name'],
],
];
chado_create_custom_table('license', $schema, TRUE, NULL, FALSE);
}
/**
*
*/
function tripal_file_add_file_license_table() {
$schema = [
'table' => 'file_license',
'fields' => [
'file_license_id' => [
'type' => 'serial',
'not null' => TRUE
],
'file_id' => [
'type' => 'int',
'not null' => TRUE
],
'license_id' => [
'type' => 'int',
'not null' => TRUE
],
],
'primary key' => ['file_license_id'],
'unique keys' => [
'file_license_c1' => ['file_id', 'license_id'],
],
'indexes' => [
'file_license_idx1' => ['file_id'],
'file_license_idx2' => ['license_id'],
],
'foreign keys' => [
'file' => [
'table' => 'file',
'columns' => [
'file_id' => 'file_id',
],
],
'license' => [
'table' => 'license',
'columns' => [
'license_id' => 'license_id',
],
],
],
];
chado_create_custom_table('file_license', $schema, TRUE, NULL, FALSE);
}
/**
* A simple function that lists supported base tables.
*
* We want to be specific about what these supported tables
* are because we don't want to accidentaly support any custom table
* that might have a _file suffix.
*/
function tripal_file_get_linked_tables() {
return [
'analysis', 'assay', 'biomaterial', 'cv', 'eimage',
'feature', 'featuremap', 'library', 'nd_protocol', 'organism',
'phylotree', 'project', 'pub', 'stock', 'stockcollection', 'study'
];
}
/**
* Creates the set of supported linker tables.
*/
function tripal_file_add_linker_tables() {
$linked_tables = tripal_file_get_linked_tables();
foreach ($linked_tables as $linked_table) {
$linked_schema = chado_get_schema($linked_table);
$pkey = $linked_schema['primary key'][0];
$linker_table = $linked_table . '_file';
$schema = [
'table' => $linker_table,
'fields' => [
$linker_table . '_id' => [
'size' => 'big',
'type' => 'serial',
'not null' => TRUE
],
'file_id' => [
'size' => 'big',
'type' => 'int',
'not null' => TRUE
],
$pkey => [
'size' => 'big',
'type' => 'int',
'not null' => TRUE
],
'rank' => [
'type' => 'int',
'not null' => TRUE,
'default' => 0
],
],
'primary key' => [$linker_table . '_id'],
'unique keys' => [
$linker_table . '_c1' => ['file_id', $pkey],
],
'indexes' => [
$linker_table . '_idx1' => ['file_id'],
$linker_table . '_idx2' => [$pkey],
],
'foreign keys' => [
'file' => [
'table' => 'file',
'columns' => [
'file_id' => 'file_id',
],
],
$linked_table => [
'table' => $linked_table,
'columns' => [
$pkey => $pkey,
],
],
],
];
chado_create_custom_table($linker_table, $schema, TRUE, NULL, FALSE);
}
}
/**
*
*/
function tripal_file_add_default_licenses() {
// Public Domain license
$license = new ChadoRecord('license');
$license->setValues([
'name' => 'Public Domain',
]);
if (!$license->find()) {
$license->setValues([
'name' => 'Public Domain',
'summary' => 'The data have no known copyrights or restrictions and ' .
'can be freely used by anyone.'
]);
$license->insert();
}
// CC 1.0 license
$license = new ChadoRecord('license');
$uri = 'https://creativecommons.org/publicdomain/zero/1.0/legalcode';
$license->setValues([
'uri' => $uri,
]);
if (!$license->find()) {
$license->setValues([
'name' => 'CC0 1.0 Universal (CC0 1.0) Public Domain Dedication',
'summary' => 'The person who associated a work with this deed has ' .
'dedicated the work to the public domain by waiving all of his or ' .
'her rights to the work worldwide under copyright law, including all ' .
'related and neighboring rights, to the extent allowed by law. ' .
'You can copy, modify, distribute and perform the work, even for ' .
'commercial purposes, all without asking permission.',
'uri' => $uri,
]);
$license->insert();
}
// CC 4.0 license
$license = new ChadoRecord('license');
$uri = 'https://creativecommons.org/licenses/by/4.0/legalcode';
$license->setValues([
'uri' => $uri,
]);
if (!$license->find()) {
$license->setValues([
'name' => 'Creative Commons Attribution 4.0 International Public License',
'summary' => 'You are free to copy and redistribute the material ' .
'in any medium or format, remix, transform, and build upon the '.
'material for any purpose, even commercially. The licensor cannot '.
'revoke these freedoms as long as you follow the license terms. ' .
'You must give appropriate credit, provide a link to the license, '.
'and indicate if changes were made. You may do so in any reasonable ' .
'manner, but not in any way that suggests the licensor endorses you ' .
'or your use. You may not apply legal terms or technological measures ' .
'that legally restrict others from doing anything the license permits.',
'uri' => $uri,
]);
$license->insert();
}
global $user;
$bundle = tripal_load_bundle_entity(['accession' => 'schema:license']);
$args = [
[
'bundle_name' => $bundle->name,
'filters' => [],
],
];
return tripal_add_job("Publish " . $bundle->label . " records.",
'tripal_chado', 'chado_publish_records', $args,
$user->uid, 10, $includes);
}
/**
* Adds the terms for the linked table columns.
*/
function tripal_file_add_linker_tables_terms() {
// Terms for linker tables
$linked_tables = tripal_file_get_linked_tables();
foreach ($linked_tables as $linked_table) {
$linked_schema = chado_get_schema($linked_table);
$pkey = $linked_schema['primary key'][0];
$linker_table = $linked_table . '_file';
// Add the term for rank.
$term = chado_get_cvterm(['id' => 'OBCS:0000117']);
chado_associate_semweb_term($linker_table, 'rank', $term);
}
}
/**
* Repopulates db2cv materialized view.
*/
function tripal_file_repopulate_db2cv_mview($jobname='Repopulating db2cv_mview') {
global $user;
$sql = "SELECT mview_id FROM [tripal_mviews] WHERE modulename=:modulename AND name=:name";
$args = [':modulename' => 'tripal_chado', ':name' => 'db2cv_mview'];
$mview_id = chado_query($sql, $args)->fetchField();
tripal_add_job(
$jobname,
'tripal_chado',
'chado_populate_mview',
[$mview_id],
$user->uid
);
}
/**
* Add default licenses
*/
function tripal_file_update_7100() {
try {
tripal_file_add_default_licenses();
tripal_file_repopulate_db2cv_mview('Repopulating db2cv_mview to fix legacy SOFP');
}
catch (\PDOException $e) {
$error = $e->getMessage();
throw new DrupalUpdateException('Could not perform update: '. $error);
}
}
/**
* Add support for displayed filename.
*/
function tripal_file_update_7101() {
$transaction = db_transaction();
try {
// Add 'filename' column to fileloc table, this holds the filename presented to
// the user. Do nothing if it already exists, as will occur on a new install.
if (!chado_column_exists('fileloc', 'filename')) {
$sql = "ALTER TABLE ONLY {fileloc} ADD COLUMN filename TEXT";
chado_query($sql, []);
$sql = "COMMENT ON COLUMN {fileloc}.filename IS :comment";
$column_comment = 'The short name of the uri as displayed to the user.';
chado_query($sql, [':comment' => $column_comment]);
// The CVterm for the new column is added as of this update, data:1050 = 'File name'.
tripal_file_add_terms();
}
}
catch (\PDOException $e) {
$transaction->rollback();
$error = $e->getMessage();
throw new DrupalUpdateException('Could not perform update: '. $error);
}
}
/**
* Add missing schema for filename column
*/
function tripal_file_update_7102() {
$filename_schema = [
'type' => 'text',
'not null' => FALSE,
'description' => t('The short name of the uri as displayed to the user.'),
];
$transaction = db_transaction();
try {
// Retrieve the table_id of the fileloc custom table, this will be
// needed to update the schema.
$sql = "SELECT table_id FROM [tripal_custom_tables] WHERE table_name='fileloc'";
$fileloc_table_id = chado_query($sql, [])->fetchObject()->table_id;
// Update the schema to add the new column for the fileloc custom table
// by getting the current schema, adding in filename schema, and updating
// the schema stored in public.tripal_custom_tables.
$schema = chado_get_schema('fileloc');
$schema['fields']['filename'] = $filename_schema;
$fields = ['schema' => serialize($schema)];
db_update('tripal_custom_tables')
->fields($fields)
->condition('table_id', $fileloc_table_id, '=')
->execute();
}
catch (\PDOException $e) {
$transaction->rollback();
$error = $e->getMessage();
throw new DrupalUpdateException('Could not perform update: '. $error);
}
}
/**
* Add the file_relationship table.
*/
function tripal_file_update_7103() {
$transaction = db_transaction();
try {
tripal_file_add_file_relationship_table();
}
catch (\PDOException $e) {
$transaction->rollback();
$error = $e->getMessage();
throw new DrupalUpdateException('Could not perform update: '. $error);
}
}