You are here

function uc_country_update in Ubercart 7.3

Same name and namespace in other branches
  1. 5 uc_store/uc_store.module \uc_country_update()
  2. 6.2 uc_store/uc_store.admin.inc \uc_country_update()

Updates a country definition to a specific CIF file version.

Parameters

$country_id: The ISO 3166-1 numeric country code.

$version: Version number of CIF file.

1 string reference to 'uc_country_update'
uc_store_menu in uc_store/uc_store.module
Implements hook_menu().

File

uc_store/uc_store.countries.inc, line 324
Store administration forms for country and address handling.

Code

function uc_country_update($country_id, $version) {
  $result = db_query("SELECT * FROM {uc_countries} WHERE country_id = :id", array(
    ':id' => $country_id,
  ));
  if (!($country = $result
    ->fetchObject())) {
    drupal_set_message(t('Attempted to update an invalid country.'));
    drupal_goto('admin/store/settings/countries');
  }
  if ($version < $country->version) {
    drupal_set_message(t('You cannot update to a previous version.'));
    drupal_goto('admin/store/settings/countries');
  }
  $func_base = _uc_country_import_include($country_id, $version);
  if ($func_base !== FALSE) {
    $func = $func_base . '_update';
    if (function_exists($func)) {
      for ($i = $country->version + 1; $i <= $version; $i++) {
        $func($i);
      }
    }
    db_update('uc_countries')
      ->fields(array(
      'version' => $version,
    ))
      ->condition('country_id', $country_id)
      ->execute();
    drupal_set_message(t('Country update complete.'));
  }
  else {
    drupal_set_message(t('Attempted to update an invalid country.'));
  }
  drupal_goto('admin/store/settings/countries');
}