-
Notifications
You must be signed in to change notification settings - Fork 0
/
tripal_ws_brapi.install
162 lines (133 loc) · 4.4 KB
/
tripal_ws_brapi.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
<?php
/**
* @file
* Contains actions performed during install/uninstall.
*/
// API.
module_load_include('inc', 'tripal_ws_brapi', 'includes/api');
/**
* Implements hook_enable().
* Set default configurations.
*/
function tripal_ws_brapi_enable() {
// Use configuration file to set default settings upon install.
include_once 'includes/config.inc';
drupal_set_message('Setting Configuration...');
drupal_set_message("Module Name: $config_module_name");
drupal_set_message("Version: $config_version");
drupal_set_message("Resultset Limit: $config_resultset_limit");
drupal_set_message("Supported Method(s): $config_supported_method");
drupal_set_message("Webservices Root Path: [your drupal site]/$config_menu_level");
drupal_set_message("Override Hook: $config_hook");
// Module name.
variable_set('tripal_ws_brapi_modulename', $config_module_name);
// Default values:
// BrAPI version 1.3
// Major version number, default minor version in a major version numbur
// and all sub-version numbers belonging to a major version number.
$default_ver = ['ver' => 1, 'default' => $config_version, 'all' => [$config_version]];
variable_set($config_module_name . '_v1', $default_ver);
// Resultset limit.
variable_set($config_module_name . '_resultset_limit', $config_resultset_limit);
// HTTP request method supported.
variable_set($config_module_name . '_supported_method', $config_supported_method);
// Menu levels/prefix.
variable_set($config_module_name . '_menu_level', $config_menu_level);
// Hook string, used by implementing module.
variable_set($config_module_name . '_hook', $config_hook);
// Allow override hook.
variable_set($config_module_name . '_allow_override_hook', $config_allow_override_hook);
}
/**
* Implements hook_disable().
* Remove configurations.
*/
function tripal_ws_brapi_disable() {
// Clear system variables
// Module name
$module = tripal_ws_get_module_info();
$config_module_name = $module['module'];
variable_del($module['var_name']);
// Default values:
// Version. Major versions 1-10 in the configuration.
for($i = 1; $i <= 10; $i++) {
$conf_ver = $config_module_name . '_v' . $i;
if (variable_get($conf_ver)) {
variable_del($conf_ver);
}
}
// Resultset limit.
variable_del($config_module_name . '_resultset_limit');
// HTTP request method supported.
variable_del($config_module_name . '_supported_method');
// Menu levels/prefix.
variable_del($config_module_name . '_menu_level');
// Hook string, used by implementing module.
variable_del($config_module_name . '_hook');
// Allow override hook.
variable_del($config_module_name . '_allow_override_hook');
// Calls.
$c = tripal_ws_get_calls();
if ($c) {
$calls = array_keys($c);
unset($c);
foreach($calls as $call) {
$var_name = $config_module_name . '_' . $call;
$var_value = variable_get($var_name);
if ($var_value) {
variable_del($var_name);
}
}
}
// Schema.
$del = "DROP TABLE IF EXISTS {tripal_ws_brapi_search_request}";
chado_query($del);
}
/**
* Implements hook_schema().
* Table definition used by search service.
* Described in https://brapi.docs.apiary.io/#introduction/search-services.
*/
function tripal_ws_brapi_schema() {
$schema = [];
$schema['tripal_ws_brapi_search_request'] = [
'description' => 'Storage for search requests',
'fields' => [
'id' => [
'description' => 'The primary identifier',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE
],
'search_request_id' => [
'description' => 'Hash code used to reference a row',
'type' => 'varchar',
'length' => 30,
'not null' => TRUE
],
'search_request_type' => [
'description' => 'Call title making the search request',
'type' => 'varchar',
'length' => 30,
'not null' => TRUE
],
'search_request_parameter' => [
'description' => 'Parameter to the search request',
'type' => 'text',
],
'request' => [
'description' => 'Number of times requested',
'type' => 'varchar',
'length' => 255
],
'search_request_created' => [
'description' => 'Timestamp, request created',
'type' => 'varchar',
'length' => 30,
'not null' => TRUE,
]
],
'primary key' => ['id']
];
return $schema;
}