You are here

uc_addresses.install in Ubercart Addresses 5

File

uc_addresses.install
View source
<?php

/**
 * Implementation of hook_install().
 */
function uc_addresses_install() {
  drupal_set_message(t('Beginning installation of uc_addresses module.'));
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {uc_addresses} (\n\taid integer unsigned not null,\n        uid integer unsigned not null,\n        first_name varchar(32) not null,\n        last_name varchar(32) not null,\n        phone varchar(32) not null,\n        company varchar(64) not null,\n        street1 varchar(64) not null,\n        street2 varchar(64) not null,\n        city varchar(32) not null,\n        zone mediumint(9) not null,\n        postal_code varchar(10) not null,\n        country mediumint(9) not null,\n\taddress_name varchar(20),\n        created int(11) not null,\n        modified int(11) not null,\n        PRIMARY KEY (aid),\n\tINDEX aid_uid_idx (aid, uid)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("CREATE TABLE {uc_addresses_defaults} (\n\taid integer unsigned not null,\n        uid integer unsigned not null,\n        PRIMARY KEY (aid, uid)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      $success = TRUE;
      break;
    case 'pgsql':
      db_query("CREATE TABLE {uc_addresses} (\n\taid integer not null default 0,\n        uid integer not null default 0,\n        first_name varchar(32) not null default '',\n        last_name varchar(32) not null default '',\n        phone varchar(32) not null default '',\n        company varchar(64) not null default '',\n        street1 varchar(64) not null default '',\n        street2 varchar(64) not null default '',\n        city varchar(32) not null default '',\n        zone integer not null default 0,\n        postal_code varchar(10) not null default '',\n        country integer not null default 0,\n\taddress_name varchar(20) default '',\n        created integer not null default 0,\n        modified integer not null default 0,\n        PRIMARY KEY (aid)\n      );");
      db_query("CREATE INDEX {uc_addresses}_aid_uid_idx ON {uc_addresses} (aid, uid)");
      db_query("CREATE TABLE {uc_addresses_defaults} (\n\taid integer not null default 0,\n        uid integer not null default 0,\n        PRIMARY KEY (aid, uid)\n      );");
      $success = TRUE;
      break;
    default:
      drupal_set_message(t('Unsupported database.'));
  }
  if ($success) {
    drupal_set_message(t('The uc_addresses table was installed successfully.'));
  }
  else {
    drupal_set_message(t('The installation of the uc_addresses module was unsuccessful.'), 'error');
  }
}

/**
 * First update: remove the old incorrect sequence number name and add
 * the correct new one. Copy over the sequence number.
 */
function uc_addresses_update_1() {
  $items = array();
  $seq = db_query("SELECT * FROM {sequences} WHERE name = 'uc_addresses'");
  if (db_num_rows($seq) == 1) {
    $obj = db_fetch_object($seq);
    $items[] = update_sql("DELETE FROM {sequences} WHERE name = 'uc_addresses'");
    $items[] = update_sql("INSERT INTO {sequences} (name, id) VALUES('{uc_addresses}_aid'," . $obj->id . ")");
  }
  return $items;
}

/**
 * Second update: add nickname field.
 */
function uc_addresses_update_2() {
  $items = array();
  $items[] = update_sql("ALTER TABLE {uc_addresses} ADD COLUMN address_name VARCHAR(20) DEFAULT NULL AFTER country");
  return $items;
}

/**
 * Implementation of hook_uninstall().
 */
function uc_addresses_uninstall() {
  db_query("DROP TABLE {uc_addresses}");
  db_query("DROP TABLE {uc_addresses_defaults}");
  db_query("DELETE FROM {sequences} WHERE name = 'uc_addresses'");
  db_query("DELETE FROM {variable} WHERE name LIKE 'uc_addresses%'");
}

Functions

Namesort descending Description
uc_addresses_install Implementation of hook_install().
uc_addresses_uninstall Implementation of hook_uninstall().
uc_addresses_update_1 First update: remove the old incorrect sequence number name and add the correct new one. Copy over the sequence number.
uc_addresses_update_2 Second update: add nickname field.