function googleanalytics_update_6002 in Google Analytics 7
Same name and namespace in other branches
- 5 googleanalytics.install \googleanalytics_update_6002()
- 6.4 googleanalytics.install \googleanalytics_update_6002()
- 6 googleanalytics.install \googleanalytics_update_6002()
- 6.2 googleanalytics.install \googleanalytics_update_6002()
- 6.3 googleanalytics.install \googleanalytics_update_6002()
- 7.2 googleanalytics.install \googleanalytics_update_6002()
Upgrade role settings and per user tracking settings of "User 1" and remove outdated tracking variables.
File
- ./
googleanalytics.install, line 120 - Installation file for Google Analytics module.
Code
function googleanalytics_update_6002() {
// Upgrade enabled/disabled roles to new logic (correct for upgrades from 5.x-1.4 and 6.x-1.0).
$roles = array();
$messages = array();
foreach (user_roles() as $rid => $name) {
if (variable_get('googleanalytics_track_' . $rid, FALSE)) {
// Role ID is activated for user tracking.
$roles[$rid] = $rid;
$messages[] = t('Enabled page tracking for role: @name.', array(
'@name' => $name,
));
}
else {
$messages[] = t('Disabled page tracking for role: @name.', array(
'@name' => $name,
));
}
}
variable_set('googleanalytics_roles', $roles);
// Upgrade disabled tracking of "user 1" to new logic.
if (!($track_user1 = variable_get('googleanalytics_track__user1', 1))) {
variable_set('googleanalytics_custom', 1);
// Load user 1 object, set appropriate value and save new user settings back.
$account = user_load(1);
$account = user_save($account, array(
'data' => array(
'googleanalytics' => array(
'custom' => 0,
),
),
), 'account');
$messages[] = t('Disabled user specific page tracking for site administrator.');
}
// Delete outdated tracking settings.
db_delete('variable')
->condition('name', db_like('googleanalytics_track_') . '%', 'LIKE')
->execute();
return implode(', ', $messages);
}