Fixed wrong update hook name
[project/google_analytics.git] / googleanalytics.install
1 <?php
2 //$Id$
3
4 /**
5 * @file
6 * Installation file for Google Analytics module.
7 */
8
9 function googleanalytics_install() {
10 variable_set('googleanalytics_visibility', 0);
11
12 // Remove tracking from all administrative pages, see http://drupal.org/node/34970.
13 $pages = array(
14 'admin',
15 'admin/*',
16 'user/*/*',
17 'node/add*',
18 'node/*/*',
19 );
20 variable_set('googleanalytics_pages', implode("\n", $pages));
21 }
22
23 function googleanalytics_uninstall() {
24 variable_del('googleanalytics_account');
25 variable_del('googleanalytics_legacy_version');
26 variable_del('googleanalytics_codesnippet_before');
27 variable_del('googleanalytics_codesnippet_after');
28 variable_del('googleanalytics_segmentation');
29 variable_del('googleanalytics_trackoutgoing');
30 variable_del('googleanalytics_trackmailto');
31 variable_del('googleanalytics_trackfiles');
32 variable_del('googleanalytics_trackfiles_extensions');
33 variable_del('googleanalytics_cache');
34 variable_del('googleanalytics_last_cache');
35 variable_del('googleanalytics_site_search');
36 variable_del('googleanalytics_trackadsense');
37 variable_del('googleanalytics_js_scope');
38 variable_del('googleanalytics_custom');
39 variable_del('googleanalytics_roles');
40 variable_del('googleanalytics_visibility');
41 variable_del('googleanalytics_pages');
42 }
43
44 /**
45 * Remove cache directory if module is disabled (or uninstalled).
46 */
47 function googleanalytics_disable() {
48 $path = file_directory_path() .'/googleanalytics';
49 if (file_exists($path)) {
50 file_delete($path .'/urchin.js');
51 file_delete($path .'/ga.js');
52 rmdir($path);
53 }
54 }
55
56
57 function googleanalytics_update_1() {
58 $ret = array();
59
60 $result = db_query("SELECT * FROM {role}");
61 while ($role = db_fetch_object($result)) {
62 // can't use empty spaces in varname
63 $role_varname = str_replace(' ', '_', $role->name);
64 variable_set('googleanalytics_track_'. $role->rid, !variable_get("googleanalytics_track_{$role_varname}", FALSE));
65 variable_del("googleanalytics_track_{$role_varname}");
66 }
67 variable_set('googleanalytics_track__user1', FALSE);
68
69 return $ret;
70 }
71
72 /**
73 * Upgrade old extension variable to new and use old name as enabled/disabled flag.
74 */
75 function googleanalytics_update_6000() {
76 $ret = array();
77
78 variable_set('googleanalytics_trackfiles_extensions', variable_get('googleanalytics_trackfiles', '7z|aac|avi|csv|doc|exe|flv|gif|gz|jpe?g|js|mp(3|4|e?g)|mov|pdf|phps|png|ppt|rar|sit|tar|torrent|txt|wma|wmv|xls|xml|zip'));
79 $trackfiles = variable_get('googleanalytics_trackfiles', '7z|aac|avi|csv|doc|exe|flv|gif|gz|jpe?g|js|mp(3|4|e?g)|mov|pdf|phps|png|ppt|rar|sit|tar|torrent|txt|wma|wmv|xls|xml|zip') ? TRUE : FALSE;
80 variable_set('googleanalytics_trackfiles', $trackfiles);
81 $ret[] = array('success' => TRUE, 'query' => 'Updated download tracking settings.');
82
83 return $ret;
84 }
85
86 function googleanalytics_update_6001() {
87 $ret = array();
88
89 variable_set('googleanalytics_visibility', 0);
90
91 // Remove tracking from all administrative pages, see http://drupal.org/node/34970.
92 $pages = array(
93 'admin*',
94 'user*',
95 'node/add*',
96 'node/*/*',
97 );
98 variable_set('googleanalytics_pages', implode("\n", $pages));
99 $ret[] = array('success' => TRUE, 'query' => 'Added page tracking to every page except the listed pages: '. implode(', ', $pages));
100
101 return $ret;
102 }
103
104 /**
105 * Upgrade role settings and per user tracking settings
106 * of "User 1" and remove outdated tracking variables.
107 */
108 function googleanalytics_update_6002() {
109 $ret = array();
110
111 // Upgrade enabled/disabled roles to new logic (correct for upgrades from 5.x-1.4 and 6.x-1.0).
112 $roles = array();
113 foreach (user_roles() as $rid => $name) {
114 if (variable_get('googleanalytics_track_'. $rid, FALSE)) {
115 // Role ID is activated for user tracking.
116 $roles[$rid] = $rid;
117 $ret[] = array('success' => TRUE, 'query' => 'Enabled page tracking for role: '. $name);
118 }
119 else {
120 $ret[] = array('success' => TRUE, 'query' => 'Disabled page tracking for role: '. $name);
121 }
122 }
123 variable_set('googleanalytics_roles', $roles);
124
125 // Upgrade disabled tracking of "user 1" to new logic.
126 if (!$track_user1 = variable_get('googleanalytics_track__user1', 1)) {
127 variable_set('googleanalytics_custom', 1);
128
129 // Load user 1 object, set appropiate value and save new user settings back.
130 $account = user_load(array('uid' => 1));
131 $account = user_save($account, array('googleanalytics' => array('custom' => 0)), 'account');
132 $ret[] = array('success' => TRUE, 'query' => 'Disabled user specific page tracking for website administrator.');
133 }
134
135 // Delete outdated tracking settings.
136 $ret[] = update_sql("DELETE FROM {variable} WHERE name LIKE 'googleanalytics_track_%'");
137
138 return $ret;
139 }
140
141 /**
142 * #262468: Clear menu cache to solve stale menu data in 5.x-1.5 and 6.x-1.1
143 */
144 function googleanalytics_update_6003() {
145 $ret = array();
146 menu_rebuild();
147 return $ret;
148 }
149
150 /**
151 * Change visibility setting for path "user/*".
152 */
153 function googleanalytics_update_6004() {
154 $ret = array();
155
156 // Orginal pages setting.
157 $pages = array(
158 'admin*',
159 'user*',
160 'node/add*',
161 'node/*/*',
162 );
163
164 $diff = array_diff($pages, preg_split('/(\r\n?|\n)/', variable_get('googleanalytics_pages', implode("\n", $pages))));
165 if (empty($diff)) {
166 // No diff to original settings found. Update with new settings.
167 $pages = array(
168 'admin*',
169 'user/*/*',
170 'node/add*',
171 'node/*/*',
172 );
173 variable_set('googleanalytics_pages', implode("\n", $pages));
174 $ret[] = array('success' => TRUE, 'query' => 'Path visibility filter setting changed from "user*" to "user/*/*".');
175 }
176 else {
177 $ret[] = array('success' => TRUE, 'query' => 'Custom path visibility filter setting found. Update skipped!');
178 }
179
180 return $ret;
181 }
182
183 /**
184 * Change visibility setting for path "admin*".
185 */
186 function googleanalytics_update_6005() {
187 $ret = array();
188
189 // Orginal pages setting.
190 $pages = array(
191 'admin*',
192 'user/*/*',
193 'node/add*',
194 'node/*/*',
195 );
196
197 $diff = array_diff($pages, preg_split('/(\r\n?|\n)/', variable_get('googleanalytics_pages', implode("\n", $pages))));
198 if (empty($diff)) {
199 // No diff to original settings found. Update with new settings.
200 $pages = array(
201 'admin',
202 'admin/*',
203 'user/*/*',
204 'node/add*',
205 'node/*/*',
206 );
207 variable_set('googleanalytics_pages', implode("\n", $pages));
208 $ret[] = array('success' => TRUE, 'query' => 'Path visibility filter setting changed from "admin*" to "admin" and "admin/*".');
209 }
210 else {
211 $ret[] = array('success' => TRUE, 'query' => 'Custom path visibility filter setting found. Update skipped!');
212 }
213
214 return $ret;
215 }
216
217 /**
218 * Upgrade custom javascript settings.
219 */
220 function googleanalytics_update_6006() {
221 $ret = array();
222
223 variable_set('googleanalytics_codesnippet_before', variable_get('googleanalytics_codesnippet', ''));
224 variable_del('googleanalytics_codesnippet');
225 $ret[] = array('success' => TRUE, 'query' => 'Upgraded custom javascript codesnippet setting.');
226
227 return $ret;
228 }
229
230 /**
231 * Remove "User identifier" and "User name" from segmentation fields.
232 *
233 * This is a data protection and privacy law change. For more information see Google Analytics
234 * terms of use section 8.1 (http://www.google.com/analytics/en-GB/tos.html).
235 */
236 function googleanalytics_update_6007() {
237 $ret = array();
238
239 $profile_fields = variable_get('googleanalytics_segmentation', array());
240 unset($profile_fields['uid']);
241 unset($profile_fields['name']);
242 variable_set('googleanalytics_segmentation', $profile_fields);
243 $ret[] = array('success' => TRUE, 'query' => 'Removed "User identifier" and "User name" from segmentation fields.');
244
245 return $ret;
246 }
247
248 /**
249 * Update list of default file extensions.
250 */
251 function googleanalytics_update_6008() {
252 $ret = array();
253
254 if (variable_get('googleanalytics_trackfiles_extensions', '') == '7z|aac|avi|csv|doc|exe|flv|gif|gz|jpe?g|js|mp(3|4|e?g)|mov|pdf|phps|png|ppt|rar|sit|tar|torrent|txt|wma|wmv|xls|xml|zip') {
255 variable_set('googleanalytics_trackfiles_extensions', '7z|aac|arc|arj|asf|asx|avi|bin|csv|doc|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mp(2|3|4|e?g)|mov(ie)?|msi|msp|pdf|phps|png|ppt|qtm?|ra(m|r)?|sea|sit|tar|tgz|torrent|txt|wav|wma|wmv|wpd|xls|xml|z|zip');
256 }
257 $ret[] = array('success' => TRUE, 'query' => 'The default extensions for download tracking have been updated.');
258
259 return $ret;
260 }