-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchado_linker_fields.install
208 lines (185 loc) · 6.28 KB
/
chado_linker_fields.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
<?php
/**
* @file
*
* Installation of the chado_linker_fields module
*/
/**
* Implements hook_requirements().
*/
function chado_linker_fields_requirements($phase) {
$requirements = [];
$minimum_version = '7.x-3.10';
if ($phase == 'install') {
if (!module_exists('tripal')) {
$requirements['chado_linker_fields-tripal'] = [
'title' => "chado_linker_fields",
'value' => "ERROR: You must have Tripal $minimum_version or later installed to use this module.",
'severity' => REQUIREMENT_ERROR,
];
}
// Requires tripal version >= '7.x-3.10'. '4.x' will also return -1 and trigger incorrect version
else {
$tripal_info = system_get_info('module', 'tripal');
$tripal_version = $tripal_info['version'];
$status = version_compare($tripal_version, $minimum_version);
if ( $status < 0 ) {
$requirements['chado_linker_fields-tripal'] = [
'title' => "chado_linker_fields",
'value' => "ERROR: Tripal version $tripal_version is below the required version $minimum_version to use this module.",
'severity' => REQUIREMENT_ERROR,
];
}
}
// Make sure chado is installed.
if (!$GLOBALS["chado_is_installed"]) {
$requirements['chado_linker_fields-chado'] = [
'title' => "chado_linker_fields",
'value' => "ERROR: Chado is not installed. Version 1.3 must be installed before this module can be enabled",
'severity' => REQUIREMENT_ERROR,
];
}
// Requires chado version 1.3
else {
$chado_version = chado_get_version();
if ($chado_version < '1.3') {
$requirements['chado_linker_fields-chado'] = [
'title' => "chado_linker_fields",
'value' => "ERROR: Chado version is $chado_version, this module requires version 1.3",
'severity' => REQUIREMENT_ERROR,
];
}
}
}
return $requirements;
}
/**
* Implements hook_install().
*
* Performs actions when the module is first installed.
*
* @ingroup chado_linker_fields
*/
function chado_linker_fields_install() {
// Add cv terms used by this module's fields that are not in core Tripal.
chado_linker_fields_add_cv_terms();
// Initialize field configuration variables.
variable_set('chado_linker_field_max_delta', 200);
variable_set('chado_linker_field_max_height', 200);
}
/**
* Implements hook_uninstall().
*
* Performs actions when the module is uninstalled.
*
* @ingroup chado_linker_fields
*/
function chado_linker_fields_uninstall() {
// Uninstall should remove the fields from this module from
// any content types currently using them.
remove_chado_linker_fields();
// Remove configuration variables specific to this module.
variable_del('chado_linker_field_max_delta');
variable_del('chado_linker_field_max_height');
// CV terms defined by this module are not removed on uninstall.
}
/**
* Add CV terms used by this module
*/
function chado_linker_fields_add_cv_terms() {
// For chado_linker__analysis field.
chado_insert_cvterm([
'id' => 'NCIT:C25391',
'name' => 'Analysis',
'cv_name' => 'ncit',
'definition' => 'Examination and interpretation; the process of identifying an issue to be understood and'
. ' addressed, modelling the issue, investigating the model results, interpreting the results,'
. ' and possibly making a recommendation. The concept also refers to the examination and study'
. ' of a whole in terms of the parts composing it.',
]);
// For chado_linker__assay field.
chado_insert_cvterm([
'id' => 'NCIT:C60819',
'name' => 'Assay',
'cv_name' => 'ncit',
'definition' => 'A qualitative or quantitative analysis performed to determine the amount of a particular'
. ' constituent in a sample or the biological or pharmacological properties of a drug.',
]);
// For chado_linker__biomaterial field.
chado_insert_cvterm([
'id' => 'NCIT:C43376',
'name' => 'Biologically-Derived Material',
'cv_name' => 'ncit',
'definition' => 'Natural substances derived from living organisms such as cells, tissues, proteins, and DNA.',
]);
// For chado_linker__feature field.
chado_insert_cvterm([
'id' => 'NCIT:C73619',
'name' => 'Feature',
'cv_name' => 'ncit',
'definition' => 'A prominent or identifiable aspect, region, or site of interest',
]);
// For chado_linker__organism field.
chado_insert_cvterm([
'id' => 'NCIT:C14250',
'name' => 'Organism',
'cv_name' => 'ncit',
'definition' => 'A living entity.',
]);
// For chado_linker__stock field.
chado_insert_cvterm([
'id' => 'NCIT:C48288',
'name' => 'Stock',
'cv_name' => 'ncit',
'definition' => 'The merchandise that a shop has on hand.',
]);
// For chado_linker__study field.
chado_insert_cvterm([
'id' => 'NCIT:C63536',
'name' => 'Study',
'cv_name' => 'ncit',
'definition' => 'A detailed examination, analysis, or critical inspection of a subject designed'
. ' to discover facts about it.',
]);
// For summary when too many records to display.
chado_insert_cvterm([
'id' => 'NCIT:C25463',
'name' => 'Count',
'cv_name' => 'ncit',
'definition' => 'Determining the number or amount of something.',
]);
}
/**
* Remove fields defined by this module from all content types.
*/
function remove_chado_linker_fields() {
// Fields defined by this module
$field_ids = [
'NCIT:C25391' => 'analysis',
'NCIT:C60819' => 'assay',
'NCIT:C43376' => 'biomaterial',
'NCIT:C73619' => 'feature',
'data:C73619' => 'featuremap',
'NCIT:C14250' => 'organism',
'NCIT:C47885' => 'project',
'NCIT:C48288' => 'stock',
'NCIT:C63536' => 'study',
];
// Find and delete any instances of these fields
$instances = field_info_instances('TripalEntity');
$n_deleted = 0;
foreach ($instances as $entity_type => $entity_info) {
foreach ($entity_info as $field_name => $field_info) {
$settings = $field_info['settings'];
$id = $settings['term_vocabulary'] . ':' . $settings['term_accession'];
if (isset($field_ids[$id])) {
// Delete the field $field_name from $entity_type
field_delete_field($field_name);
$n_deleted++;
}
}
}
if ($n_deleted) {
field_purge_batch($n_deleted);
}
}