This repository has been archived by the owner on Nov 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfarmosnws.install
150 lines (119 loc) · 4.62 KB
/
farmosnws.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
<?php
/**
* implements hook_install()
*/
function farmosnws_install() {
// add the quantity types
// get the vocabulary id
$vocab_qty_units = taxonomy_vocabulary_machine_name_load('farm_quantity_units');
// list of terms to add
$terms_qty_list = array('Inches', 'MPH', 'Miles', 'Knots', 'KM', 'Degrees');
$terms_qty_list .= array('KPH', 'Percent', 'Fahrenheit', 'Celsius', 'Direction');
// check if the term exists, if it does not then add it
foreach($terms_qty_list as $term_qty_item) {
$taxterm = taxonomy_get_term_by_name($term_qty_item);
if (count($taxterm) == 0) {
$tax_qty_term = new stdClass();
$tax_qty_term->name = $term_qty_item;
$tax_qty_term->vid = $vocab_qty_units->vid;
taxonomy_term_save($tax_qty_term);
farmosnws_display_status("Created " . $term_qty_item . " taxonomy term.", FALSE);
}
else {
farmosnws_display_status("Matched taxonomy term " . $term_qty_item, FALSE);
}
}
// set default variable values
variable_set('farmosnws_delete_xml', 'yes');
variable_set('farmosnws_cron_last', 0);
variable_set('farmosnws_locations', 'KMGM');
variable_set('farmosnws_log_dewpoint', 1);
variable_set('farmosnws_log_pressures', 1);
variable_set('farmosnws_log_temperature', 1);
variable_set('farmosnws_log_visibility', 1);
variable_set('farmosnws_log_weather', 1);
variable_set('farmosnws_log_winddirection', 1);
variable_set('farmosnws_log_windspeed', 1);
}
/**
* implements hook_enable()
*/
function farmosnws_enable() {
// notice to visit configuration page to set initial values for variables
farmosnws_display_warning("Visit the module " . l(t("configuration page"), 'admin/config/farm/farmosnws') . " to complete module setup.", TRUE);
farmosnws_check_farmos_measurements();
farmosnws_check_cron_time();
}
/**
* implements hook_uninstall()
*/
function farmosnws_uninstall() {
// delete all the variables created by the module
$query = "select name from {variable} where name like :varname";
$result = db_query($query, array(':varname' => db_like('farmosnws') . '%'));
foreach($result as $row) {
variable_del($row->name);
} // end foreach
menu_rebuild();
farmosnws_display_status("FarmOS NWS Module has been uninstalled", FALSE);
} // end function
/**
* Use FarmOS unit of measurement setting, limit the number of feed pulls from
* NWS, and update new and existing variables.
*/
function farmosnws_update_7201(&$sandbox) {
// get the vocabulary id
$vocab_qty_units = taxonomy_vocabulary_machine_name_load('farm_quantity_units');
// list of terms to add
$terms_qty_list = array('KPH', 'Kilometers', 'Degrees', 'Percent');
// check if the term exists, if it does not then add it
foreach($terms_qty_list as $term_qty_item) {
$taxterm = taxonomy_get_term_by_name($term_qty_item);
if (count($taxterm) == 0) {
$tax_qty_term = new stdClass();
$tax_qty_term->name = $term_qty_item;
$tax_qty_term->vid = $vocab_qty_units->vid;
taxonomy_term_save($tax_qty_term);
farmosnws_display_status("Created " . $term_qty_item . " taxonomy term.", FALSE);
}
else {
farmosnws_display_status("Matched taxonomy term " . $term_qty_item, FALSE);
}
}
// delete unused variables
variable_del('farmosnws_temp_units');
// set new variables being used
variable_set('farmosnws_cron_last', 0);
variable_set('farmosnws_log_dewpoint', 1);
variable_set('farmosnws_log_pressures', 1);
variable_set('farmosnws_log_temperature', 1);
variable_set('farmosnws_log_visibility', 1);
variable_set('farmosnws_log_weather', 1);
variable_set('farmosnws_log_winddirection', 1);
variable_set('farmosnws_log_windspeed', 1);
// fix variable that was saved with wrong name
$delete_feed_value = variable_get('farmosnws_del_process_feed', 'no');
variable_set('farmosnws_delete_xml', $delete_feed_value);
variable_del('farmosnws_del_process_feed');
}
function farmosnws_update_7202() {
// Create a user account for loading data
$account = array(
'name' => 'farmosnwsdata',
'mail' => '[email protected]',
'pass' => user_password(20),
'status' => 0,
'init' => '[email protected]',
'roles' => array(
DRUPAL_AUTHENTICATED_RID => 'authenticated user',
),
'access' => REQUEST_TIME,
'is_new' => TRUE
);
// save the account
$account = user_save(null, $account);
// set the UID to save data in case user name or other details are changed
variable_set('farmosnws_data_uid', $account->uid);
// save data loaded as the user that has been created
variable_set('farmosnws_save_as_user', 'yes');
} // end farmosnws_update_7202