You are here

function googleanalytics_update_6002 in Google Analytics 5

Same name and namespace in other branches
  1. 6.4 googleanalytics.install \googleanalytics_update_6002()
  2. 6 googleanalytics.install \googleanalytics_update_6002()
  3. 6.2 googleanalytics.install \googleanalytics_update_6002()
  4. 6.3 googleanalytics.install \googleanalytics_update_6002()
  5. 7.2 googleanalytics.install \googleanalytics_update_6002()
  6. 7 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 107
Installation file for Google Analytics module.

Code

function googleanalytics_update_6002() {
  $ret = array();

  // Upgrade enabled/disabled roles to new logic (correct for upgrades from 5.x-1.4 and 6.x-1.0).
  $roles = array();
  foreach (user_roles() as $rid => $name) {
    if (variable_get('googleanalytics_track_' . $rid, FALSE)) {

      // Role ID is activated for user tracking.
      $roles[$rid] = $rid;
      $ret[] = array(
        'success' => TRUE,
        'query' => 'Enabled page tracking for role: ' . $name,
      );
    }
    else {
      $ret[] = array(
        'success' => TRUE,
        'query' => 'Disabled page tracking for role: ' . $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 appropiate value and save new user settings back.
    $account = user_load(array(
      'uid' => 1,
    ));
    $account = user_save($account, array(
      'googleanalytics' => array(
        'custom' => 0,
      ),
    ), 'account');
    $ret[] = array(
      'success' => TRUE,
      'query' => 'Disabled user specific page tracking for website administrator.',
    );
  }

  // Delete outdated tracking settings.
  $ret[] = update_sql("DELETE FROM {variable} WHERE name LIKE 'googleanalytics_track_%'");
  return $ret;
}