You are here

function uc_addresses_update_6200 in Ubercart Addresses 7

Same name and namespace in other branches
  1. 6.2 uc_addresses.install \uc_addresses_update_6200()

Upgrade from 6.x-1.x.

The uc_addresses_defaults table will be removed. Two columns will be added to the uc_addresses table:<br />

  • default_shipping<br />
  • default_billing

File

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

Code

function uc_addresses_update_6200() {

  // Add 'default_shipping' and 'default_billing' fields.
  db_add_field('uc_addresses', 'default_shipping', array(
    'description' => t('If the address is the default shipping address'),
    'type' => 'int',
    'size' => 'tiny',
    'not null' => TRUE,
    'default' => 0,
  ));
  db_add_field('uc_addresses', 'default_billing', array(
    'description' => t('If the address is the default billing address'),
    'type' => 'int',
    'size' => 'tiny',
    'not null' => TRUE,
    'default' => 0,
  ));

  // Get address defaults.
  $default_aids = array();
  $result = db_select('uc_addresses_defaults')
    ->fields('uc_addresses_defaults', array(
    'aid',
  ))
    ->execute();
  foreach ($result as $default) {
    $default_aids[] = $default->aid;
  }

  // Update defaults.
  if (count($default_aids) > 0) {
    $query = db_update('uc_addresses')
      ->fields(array(
      'default_shipping' => 1,
      'default_billing' => 1,
    ))
      ->condition('aid', $default_aids)
      ->execute();
  }

  // Drop table uc_addresses_defaults.
  db_drop_table('uc_addresses_defaults');

  // Setup default permissions. Authenticated users will automatically
  // be granted with permissions to manage their own addresses.
  // Note: the function user_role_grant_permissions() can't be used here
  // since it is not able to install permissions for disabled modules.
  // See also http://drupal.org/node/737816
  $permissions = array(
    'view own addresses',
    'add/edit own addresses',
    'delete own addresses',
  );
  foreach ($permissions as $name) {
    db_merge('role_permission')
      ->key(array(
      'rid' => DRUPAL_AUTHENTICATED_RID,
      'permission' => $name,
    ))
      ->fields(array(
      'module' => 'uc_addresses',
    ))
      ->execute();
  }
  return t("Ubercart Addresses has new permissions. The authenticated user automatically was granted the permissions %view_own, %edit_own and %delete_own.", array(
    '%view_own' => t('view own addresses'),
    '%edit_own' => t('add/edit own addresses'),
    '%delete_own' => t('delete own addresses'),
  ));
}