You are here

function globalredirect_update_6101 in Global Redirect 7

Same name and namespace in other branches
  1. 6 globalredirect.install \globalredirect_update_6101()

File

./globalredirect.install, line 25
Install, update and uninstall functions for the globalredirect module.

Code

function globalredirect_update_6101() {

  // Get the default settings
  drupal_load('module', 'globalredirect');
  $defaults = _globalredirect_get_settings(TRUE);

  // Define a settings array based on the variables already set (or their defaults)
  $settings = array(
    'deslash' => (int) variable_get('globalredirect_deslash', 1),
    'nonclean_to_clean' => (int) variable_get('globalredirect_nonclean2clean', 1),
    'trailing_zero' => variable_get('globalredirect_trailingzero', 0),
    'menu_check' => (int) variable_get('globalredirect_menu_check', 0),
    'case_sensitive_urls' => (int) variable_get('globalredirect_case_sensitive_urls', 1),
  );

  // If a setting matches the default value, unset it (we wont need to store it)
  foreach ($settings as $key => $value) {

    // We used to use -1 for disabled, convert this to 0 for the new diabled
    if ($value == -1) {
      $settings[$key] = 0;
    }

    // Now compare the value to the defaults. Only store if an "override".
    if ($value == $defaults[$key]) {
      unset($settings[$key]);
    }
  }

  // Save the settings in a single array rather than individual keys
  if (!empty($settings)) {
    variable_set('globalredirect_settings', $settings);
  }

  // Remove all the old settings
  variable_del('globalredirect_deslash');
  variable_del('globalredirect_nonclean2clean');
  variable_del('globalredirect_trailingzero');
  variable_del('globalredirect_trailingzero');
  variable_del('globalredirect_menu_check');
  variable_del('globalredirect_case_sensitive_urls');
}