Sync latest D6 code to HEAD
[project/google_analytics.git] / googleanalytics.install
CommitLineData
6d129079 1<?php
60b6111f 2// $Id$
6d129079
MC
3
4function googleanalytics_install() {
60b6111f 5 variable_set('googleanalytics_visibility', 0);
6d129079 6
60b6111f 7 // Remove tracking from all administrative pages, see http://drupal.org/node/34970.
8 $pages = array(
9 'admin*',
10 'user*',
11 'node/add*',
12 'node/*/*',
13 );
14 variable_set('googleanalytics_pages', implode("\n", $pages));
68c107f3 15}
16
17function googleanalytics_uninstall() {
18 $result = db_query("DELETE FROM {variable} WHERE name LIKE 'googleanalytics_track_%'");
19
20 variable_del('googleanalytics_account');
60b6111f 21 variable_del('googleanalytics_legacy_version');
68c107f3 22 variable_del('googleanalytics_codesnippet');
23 variable_del('googleanalytics_segmentation');
60b6111f 24 variable_del('googleanalytics_trackoutgoing');
25 variable_del('googleanalytics_trackmailto');
68c107f3 26 variable_del('googleanalytics_trackfiles');
60b6111f 27 variable_del('googleanalytics_trackfiles_extensions');
68c107f3 28 variable_del('googleanalytics_cache');
60b6111f 29 variable_del('googleanalytics_last_cache');
30 variable_del('googleanalytics_site_search');
31 variable_del('googleanalytics_js_scope');
32 variable_del('googleanalytics_custom');
33 variable_del('googleanalytics_roles');
34 variable_del('googleanalytics_visibility');
35 variable_del('googleanalytics_pages');
68c107f3 36}
37
38
39function googleanalytics_update_1() {
40 $ret = array();
41
42 $result = db_query("SELECT * FROM {role}");
43 while ($role = db_fetch_object($result)) {
44 // can't use empty spaces in varname
45 $role_varname = str_replace(' ', '_', $role->name);
46 variable_set('googleanalytics_track_'. $role->rid, !variable_get("googleanalytics_track_{$role_varname}", FALSE));
47 variable_del("googleanalytics_track_{$role_varname}");
48 }
60b6111f 49 variable_set('googleanalytics_track__user1', FALSE);
50
51 return $ret;
52}
53
54function googleanalytics_update_6000() {
55 $ret = array();
56
57 variable_set('googleanalytics_trackfiles_extensions', variable_get('googleanalytics_trackfiles', GA_TRACKFILES_EXTENSIONS));
58 $trackfiles = variable_get('googleanalytics_trackfiles', GA_TRACKFILES_EXTENSIONS) ? TRUE : FALSE;
59 variable_set('googleanalytics_trackfiles', $trackfiles);
60 $ret[] = array('success' => TRUE, 'query' => 'Updated download tracking settings.');
61
62 return $ret;
63}
64
65function googleanalytics_update_6001() {
66 $ret = array();
67
68 variable_set('googleanalytics_visibility', 0);
69
70 // Remove tracking from all administrative pages, see http://drupal.org/node/34970.
71 $pages = array(
72 'admin*',
73 'user*',
74 'node/add*',
75 'node/*/*',
76 );
77 variable_set('googleanalytics_pages', implode("\n", $pages));
78 $ret[] = array('success' => TRUE, 'query' => 'Added page tracking to every page except the listed pages: '. implode(', ', $pages));
79
80 return $ret;
81}
82
83/**
84 * Upgrade role settings and per user tracking settings
85 * of "User 1" and remove outdated tracking variables.
86 */
87function googleanalytics_update_6002() {
88 $ret = array();
89
90 // Upgrade enabled/disabled roles to new logic (correct for upgrades from 5.x-1.4 and 6.x-1.0).
91 $roles = array();
92 foreach (user_roles() as $rid => $name) {
93 if (variable_get('googleanalytics_track_'. $rid, FALSE)) {
94 // Role ID is activated for user tracking.
95 $roles[$rid] = $rid;
96 $ret[] = array('success' => TRUE, 'query' => 'Enabled page tracking for role: '. $name);
97 }
98 else {
99 $ret[] = array('success' => TRUE, 'query' => 'Disabled page tracking for role: '. $name);
100 }
101 }
102 variable_set('googleanalytics_roles', $roles);
103
104 // Upgrade disabled tracking of "user 1" to new logic.
105 if (!$track_user1 = variable_get('googleanalytics_track__user1', 1)) {
106 variable_set('googleanalytics_custom', 1);
107
108 // Load user 1 object, set appropiate value and save new user settings back.
109 $account = user_load(array('uid' => 1));
110 $account = user_save($account, array('googleanalytics' => array('custom' => 0)), 'account');
111 $ret[] = array('success' => TRUE, 'query' => 'Disabled user specific page tracking for website administrator.');
112 }
113
114 // Delete outdated tracking settings.
115 $result = db_query("DELETE FROM {variable} WHERE name LIKE 'googleanalytics_track_%'");
68c107f3 116
117 return $ret;
60b6111f 118}