You are here

uc_store.install in Ubercart 5

File

uc_store/uc_store.install
View source
<?php

function uc_store_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      db_query("CREATE TABLE {uc_countries} (\n        country_id mediumint(11) NOT NULL,\n        country_name varchar(255) NOT NULL,\n        country_iso_code_2 char(2) NOT NULL,\n        country_iso_code_3 char(3) NOT NULL,\n        version smallint(11) NOT NULL default '0',\n        PRIMARY KEY (country_id),\n        KEY country_name (country_name)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("CREATE TABLE {uc_zones} (\n        zone_id mediumint(11) NOT NULL,\n        zone_country_id mediumint(11) NOT NULL default '0',\n        zone_code varchar(32) NOT NULL default '',\n        zone_name varchar(255) NOT NULL default '',\n        PRIMARY KEY (zone_id),\n        KEY zone_code (zone_code),\n        KEY zone_country_id (zone_country_id)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */");
      db_query("CREATE TABLE {uc_store_footers} (\n        `path_hash` varchar(32) NOT NULL default '',\n        `message` text NOT NULL,\n        PRIMARY KEY (path_hash)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {uc_countries} (\n        country_id integer NOT NULL default 0,\n        country_name varchar(255) NOT NULL default '',\n        country_iso_code_2 char(2) NOT NULL default '',\n        country_iso_code_3 char(3) NOT NULL default '',\n        version integer NOT NULL default '0',\n        PRIMARY KEY (country_id)\n      );");
      db_query("CREATE INDEX {uc_countries}_country_name ON {uc_countries} (country_name)");
      db_query("CREATE INDEX {uc_countries}_country_id ON {uc_countries} (country_id)");
      db_query("CREATE TABLE {uc_zones} (\n        zone_id serial NOT NULL,\n        zone_country_id integer NOT NULL default 0,\n        zone_code varchar(32) NOT NULL default '',\n        zone_name varchar(255) NOT NULL default '',\n        PRIMARY KEY (zone_id)\n      );");
      db_query("CREATE INDEX {uc_zones}_zone_code ON {uc_zones} (zone_code)");
      db_query("CREATE INDEX {uc_zones}_zone_country_id ON {uc_zones} (zone_country_id)");
      db_query("CREATE TABLE {uc_store_footers} (\n        path_hash varchar(32) NOT NULL default '',\n        message text NOT NULL default '',\n        PRIMARY KEY (path_hash)\n      )");
      break;
  }

  // Install United States and Canada by default.
  $path = drupal_get_path('module', 'uc_store');
  require_once $path . '/countries/united_states_840_1.cif';
  require_once $path . '/countries/canada_124_1.cif';
  united_states_install();
  canada_install();
}
function uc_store_uninstall() {
  db_query("DROP TABLE {uc_countries}");
  db_query("DROP TABLE {uc_zones}");
  db_query("DROP TABLE {uc_store_footers}");
  db_query("DELETE FROM {variable} WHERE name LIKE 'user_initials_%%'");
  db_query("DELETE FROM {variable} WHERE name LIKE 'uc_address_format_%%'");
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      db_query("DELETE FROM {sequences} WHERE name LIKE '{uc_zones}_zone_id'");
      break;
  }
  variable_del('uc_store_prev_time');
  variable_del('uc_store_site_id');
  variable_del('uc_store_name');
  variable_del('uc_store_owner');
  variable_del('uc_store_email');
  variable_del('uc_store_phone');
  variable_del('uc_store_fax');
  variable_del('uc_store_street1');
  variable_del('uc_store_street2');
  variable_del('uc_store_city');
  variable_del('uc_store_zone');
  variable_del('uc_store_postal_code');
  variable_del('uc_store_country');
  variable_del('uc_store_admin_page_display');
  variable_del('uc_customer_list_address');
  variable_del('uc_currency_sign');
  variable_del('uc_sign_after_amount');
  variable_del('uc_currency_thou');
  variable_del('uc_currency_dec');
  variable_del('uc_currency_prec');
  variable_del('uc_weight_unit');
  variable_del('uc_weight_format');
  variable_del('uc_weight_format_lb');
  variable_del('uc_weight_format_kg');
  variable_del('uc_weight_format_oz');
  variable_del('uc_weight_format_g');
  variable_del('uc_length_unit');
  variable_del('uc_length_format_in');
  variable_del('uc_length_format_cm');
  variable_del('uc_date_format_default');
  variable_del('uc_field_first_name');
  variable_del('uc_field_last_name');
  variable_del('uc_field_email');
  variable_del('uc_field_phone');
  variable_del('uc_field_company');
  variable_del('uc_field_address');
  variable_del('uc_field_street');
  variable_del('uc_field_street1');
  variable_del('uc_field_street2');
  variable_del('uc_field_city');
  variable_del('uc_field_zone');
  variable_del('uc_field_country');
  variable_del('uc_field_postal_code');
  variable_del('uc_address_fields');
  variable_del('uc_address_fields_required');
}
function uc_store_update_1() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("DROP TABLE IF EXISTS {uc_address_formats}");
      $ret[] = update_sql("ALTER TABLE {uc_countries} CHANGE address_format_id version SMALLINT(11) NOT NULL DEFAULT '0'");
      $ret[] = update_sql("ALTER TABLE {uc_zones} CHANGE zone_name zone_name VARCHAR(32) CHARACTER SET utf8 NOT NULL");
      break;
    case 'pgsql':
      $ret[] = update_sql("DROP TABLE IF EXISTS {uc_address_formats}");
      $ret[] = update_sql("ALTER TABLE {uc_countries} CHANGE address_format_id version SMALLINT(11) NOT NULL DEFAULT '0'");
      $ret[] = update_sql("ALTER TABLE {uc_zones} CHANGE zone_name zone_name VARCHAR(32) CHARACTER SET utf8 NOT NULL default ''");
      break;
  }
  return $ret;
}
function uc_store_update_2() {
  $ret = array();

  // Get rid of the auto_increment.
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_zones} CHANGE zone_id zone_id MEDIUMINT(11) NOT NULL");
      $ret[] = update_sql("ALTER TABLE {uc_zones} CHANGE zone_name zone_name VARCHAR(255) CHARACTER SET utf8 NOT NULL");
      $ret[] = update_sql("ALTER TABLE {uc_countries} CHANGE country_id country_id MEDIUMINT(11) NOT NULL");
      break;
    case 'pgsql':
      db_change_column($ret, 'uc_zones', 'zone_id', 'zone_id', 'integer', array(
        'not null' => true,
        'default' => 0,
      ));
      db_change_column($ret, 'uc_zones', 'zone_name', 'zone_name', 'varchar(255) CHARACTER SET utf8', array(
        'not null' => true,
        'default' => "''",
      ));
      db_change_column($ret, 'uc_countries', 'country_id', 'country_id', 'integer', array(
        'not null' => true,
        'default' => 0,
      ));
      break;
  }

  // Make the fixes for U.S.
  $ret[] = update_sql("UPDATE {uc_countries} SET country_id = 840 WHERE country_id = 223");
  $ret[] = update_sql("UPDATE {uc_zones} SET zone_country_id = 840 WHERE zone_country_id = 223");
  $ret[] = update_sql("UPDATE {uc_orders} SET delivery_country = 840 WHERE delivery_country = 223");
  $ret[] = update_sql("UPDATE {uc_orders} SET billing_country = 840 WHERE billing_country = 223");
  if (variable_get('uc_store_country', 223) == 223) {
    variable_set('uc_store_country', 840);
  }

  // Make the fixes for Canada.
  $ret[] = update_sql("UPDATE {uc_countries} SET country_id = 124 WHERE country_id = 38");
  $ret[] = update_sql("UPDATE {uc_zones} SET zone_country_id = 124 WHERE zone_country_id = 38");
  if (variable_get('uc_store_country', 223) == 38) {
    variable_set('uc_store_country', 124);
  }
  $result = db_query("SELECT zone_id FROM {uc_zones} ORDER BY zone_id DESC LIMIT 1");
  if ($row = db_fetch_object($result)) {
    $max_id = $row->zone_id;
  }
  else {
    $max_id = 1;
  }
  $ret[] = update_sql("INSERT INTO {sequences} VALUES ('{uc_zones}_zone_id', {$max_id})");
  return $ret;
}
function uc_store_update_3() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("CREATE TABLE {uc_store_footers} (\n        `path_hash` varchar(32) NOT NULL default '',\n        `message` text NOT NULL,\n        PRIMARY KEY (path_hash)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      break;
    case 'pgsql':
      $ret[] = update_sql("CREATE TABLE {uc_store_footers} (\n        path_hash varchar(32) NOT NULL default '',\n        message text NOT NULL default '',\n        PRIMARY KEY (path_hash)\n      )");
      break;
  }
  return $ret;
}
function uc_store_update_4() {
  db_query("DELETE FROM {variable} WHERE name LIKE 'uc_store_opt_in%%'");
  variable_del('uc_store_prev_time');
  return array();
}