You are here

function uc_addresses_update_7100 in Ubercart Addresses 7

Upgrade from Ubercart Addresses 6.x-2.x.

WARNING! Be sure to have the Drupal 7 version of the token module in place first before upgrading as this update function calls a function from there.

Updates all Ubercart Addresses address formats to the 7.x-1.x style. These address formats contains tokens that need to be updated to the Drupal 7 token style.

File

./uc_addresses.install, line 320
Install file for Ubercart Addresses.

Code

function uc_addresses_update_7100() {

  // Test if the install file of the token module exists.
  if (!module_load_include('install', 'token')) {
    throw new Exception(t('The contrib token module is needed to perform the upgrade.'));
  }
  $count = 0;
  $result = db_select('uc_countries')
    ->condition('version', 0, '>')
    ->fields('uc_countries', array(
    'country_id',
  ))
    ->execute();
  foreach ($result as $country) {
    $format = variable_get('uc_addresses_address_format_' . $country->country_id, NULL);
    if ($format) {

      // Update this format.
      $format = uc_addresses_update_token_text($format);
      variable_set('uc_addresses_address_format_' . $country->country_id, $format);
      $count++;
    }
  }
  return t('!number address formats have been updated to the Drupal 7 token style.', array(
    '!number' => $count,
  ));
}