You are here

function google_tag_update_7103 in GoogleTagManager 7

Same name and namespace in other branches
  1. 7.2 google_tag.install \google_tag_update_7103()

Convert toggle settings from integer to string.

File

./google_tag.install, line 169
Provides install, update, and uninstall functions.

Code

function google_tag_update_7103(&$sandbox) {
  $types = array(
    'path',
    'role',
    'status',
  );
  $count = 0;
  if (module_exists('variable_realm') && module_exists('variable_store')) {

    // i18n_variable module depends on variable_realm, variable_store
    // In the course of variable_realm_set() calls will be made to:
    // - cache_clear_all('variables', 'cache_bootstrap');
    // - cache_clear_all('variable:' . $realm . ':' . $key, 'cache_bootstrap');
    // which will clear all relevant cache tables except for cache_variable.
    // Clear the latter at end.
    $realms = variable_realm_list();
    foreach ($realms as $realm_name => $realm_title) {
      $keys = variable_realm_keys($realm_name);
      foreach ($keys as $key_name => $key_title) {
        foreach ($types as $type) {
          $name = "google_tag_{$type}_toggle";
          $value = variable_realm_get($realm_name, $key_name, $name);

          // Safer to set status toggle to 'all except' regardless of prior value.
          $value = $type == 'status' ? 0 : $value;
          if (!is_null($value)) {
            $new_value = $value ? GOOGLE_TAG_INCLUDE_LISTED : GOOGLE_TAG_EXCLUDE_LISTED;
            variable_realm_set($realm_name, $key_name, $name, $new_value, FALSE);
            $count++;
          }
        }
      }
    }
    variable_cache_clear();
  }
  else {
    global $conf;
    foreach ($types as $type) {
      $name = "google_tag_{$type}_toggle";
      if (isset($conf[$name])) {
        $new_value = $conf[$name] ? GOOGLE_TAG_INCLUDE_LISTED : GOOGLE_TAG_EXCLUDE_LISTED;
        variable_set($name, $new_value);
        $count++;
      }
    }
  }
  return t('Converted @count toggle settings', array(
    '@count' => $count,
  ));
}