You are here

uc_ups.install in Ubercart 5

File

shipping/uc_ups/uc_ups.install
View source
<?php

function uc_ups_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {uc_ups_products} (\n        `vid` mediumint(9) unsigned NOT NULL default 0,\n        `nid` mediumint(9) unsigned NOT NULL default 0,\n        `pkg_type` varchar(2) NOT NULL,\n        PRIMARY KEY (`vid`)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ;");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {uc_ups_products} (\n        vid int_unsigned NOT NULL default 0,\n        nid int_unsigned NOT NULL default 0,\n        pkg_type varchar(2) NOT NULL default '',\n        PRIMARY KEY (vid)\n      );");
      break;
  }
}
function uc_ups_uninstall() {
  db_query("DROP TABLE {uc_ups_products}");
  variable_del('uc_ups_access_license');
  variable_del('uc_ups_shipper_number');
  variable_del('uc_ups_user_id');
  variable_del('uc_ups_password');
  variable_del('uc_ups_connection_address');
  variable_del('uc_ups_services');
  variable_del('uc_ups_pickup_type');
  variable_del('uc_ups_classification');
  variable_del('uc_ups_negotiated_rates');
  variable_del('uc_ups_markup');
  variable_del('uc_ups_all_in_one');
  variable_del('uc_ups_unit_system');
  variable_del('uc_ups_insurance');
}
function uc_ups_update_1() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_ups_products} ADD COLUMN units varchar(255) NOT NULL default 'in' AFTER height");
      break;
    case 'pgsql':
      db_add_column($ret, 'uc_ups_products', 'units', 'varchar(255)', array(
        'not null' => true,
        'default' => 'in',
      ));
      break;
  }
  return $ret;
}
function uc_ups_update_2() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_ups_products} ADD COLUMN qty smallint unsigned NOT NULL default '1' AFTER pkg_type");
      break;
    case 'pgsql':
      db_add_column($ret, 'uc_ups_products', 'qty', 'smallint unsigned', array(
        'not null' => true,
        'default' => 1,
      ));
      break;
  }
  return $ret;
}
function uc_ups_update_3() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
    case 'pgsql':
      $ret[] = update_sql("ALTER TABLE {uc_ups_products} DROP COLUMN qty");
      $ret[] = update_sql("ALTER TABLE {uc_ups_products} DROP COLUMN length");
      $ret[] = update_sql("ALTER TABLE {uc_ups_products} DROP COLUMN width");
      $ret[] = update_sql("ALTER TABLE {uc_ups_products} DROP COLUMN height");
      $ret[] = update_sql("ALTER TABLE {uc_ups_products} DROP COLUMN units");
      break;
  }
  return $ret;
}
function uc_ups_update_4() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_ups_products} ADD COLUMN vid mediumint(9) unsigned NOT NULL default 0 FIRST");
      $ret[] = update_sql("ALTER TABLE {uc_ups_products} DROP INDEX nid");
      $result = db_query("SELECT nid, vid FROM {node}");
      while ($product = db_fetch_object($result)) {
        db_query("UPDATE {uc_ups_products} SET vid = %d WHERE nid = %d", $product->vid, $product->nid);
      }
      $ret[] = update_sql("ALTER TABLE {uc_ups_products} ADD PRIMARY KEY (vid)");
      break;
    case 'pgsql':
      db_add_column($ret, 'uc_ups_products', 'vid', 'integer unsigned', array(
        'not null' => true,
        'default' => 0,
      ));
      $ret[] = update_sql("ALTER TABLE {uc_ups_products} DROP CONSTRAINT {uc_ups_products}_nid_key");
      $result = db_query("SELECT nid, vid FROM {node}");
      while ($product = db_fetch_object($result)) {
        db_query("UPDATE {uc_ups_products} SET vid = %d WHERE nid = %d", $product->vid, $product->nid);
      }
      $ret[] = update_sql("ALTER TABLE {uc_ups_products} ADD PRIMARY KEY (vid)");
      break;
  }
  return $ret;
}
function uc_ups_update_5() {
  $ret = array();
  $markup = variable_get('uc_ups_markup', '0%');
  if (strpos($markup, '%') !== false) {
    variable_set('uc_ups_markup_type', 'percentage');
    variable_set('uc_ups_markup', floatval(rtrim($markup, '%')));
  }
  else {
    if (strpos($markup, '$') !== false) {
      variable_set('uc_ups_markup_type', 'currency');
      variable_set('uc_ups_markup', floatval(ltrim($markup, '$')));
    }
    else {
      if (floatval($markup)) {
        variable_set('uc_ups_markup_type', 'multiplier');
        variable_set('uc_ups_markup', floatval($markup));
      }
    }
  }
  $ret[] = array(
    'success' => true,
    'query' => 'Added UPS markup type.',
  );
  return $ret;
}
function uc_ups_update_6() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'pgsql':
      db_change_column($ret, 'uc_ups_prodcts', 'vid', 'vid', 'int_unsigned', array(
        'not null' => true,
        'default' => 0,
      ));
      db_change_column($ret, 'uc_ups_prodcts', 'nid', 'nid', 'int_unsigned', array(
        'not null' => true,
        'default' => 0,
      ));
      break;
  }
  return $ret;
}