You are here

uc_product_kit.install in Ubercart 5

File

uc_product_kit/uc_product_kit.install
View source
<?php

function uc_product_kit_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {uc_product_kits} (\n        `vid` mediumint(9) NOT NULL default 0,\n        `nid` mediumint(9) NOT NULL default 0,\n        `product_id` mediumint(9) NOT NULL,\n        `mutable` tinyint(1) NOT NULL default 0,\n        `qty` smallint(6) NOT NULL,\n        `discount` float NOT NULL default 0.0,\n        `ordering` smallint NOT NULL default 0,\n        PRIMARY KEY  (`vid`, `product_id`)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ;");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {uc_product_kits} (\n        vid integer NOT NULL default 0,\n        nid integer NOT NULL default 0,\n        product_id integer NOT NULL default 0,\n        mutable smallint NOT NULL default 0,\n        qty smallint NOT NULL default 0,\n        discount float NOT NULL default 0.0,\n        ordering smallint NOT NULL default 0,\n        PRIMARY KEY  (vid, product_id)\n      );");
      break;
  }
}
function uc_product_kit_uninstall() {
  db_query("DROP TABLE {uc_product_kits}");
  variable_del('uc_product_kit_mutable');
}
function uc_product_kit_update_1() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_product_kits} ADD PRIMARY KEY (nid, product_id)");
      $ret[] = update_sql("ALTER TABLE {uc_product_kits} ADD COLUMN mutable tinyint(1) NOT NULL default 0 AFTER product_id");
      $ret[] = update_sql("ALTER TABLE {uc_product_kits} ADD COLUMN discount float NOT NULL default 0.0 AFTER qty");
      break;
    case 'pgsql':
      $ret[] = update_sql("ALTER TABLE {uc_product_kits} ADD PRIMARY KEY (nid, product_id)");
      db_add_column($ret, 'uc_product_kits', 'mutable', 'smallint', array(
        'not null' => true,
        'default' => 0,
      ));
      db_add_column($ret, 'uc_product_kits', 'discount', 'float', array(
        'not null' => true,
        'default' => 0.0,
      ));
      break;
  }
  return $ret;
}
function uc_product_kit_update_2() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_product_kits} ADD COLUMN ordering smallint NOT NULL default 0");
      break;
    case 'pgsql':
      db_add_column($ret, 'uc_product_kits', 'ordering', 'smallint', array(
        'not null' => true,
        'default' => 0,
      ));
      break;
  }
  return $ret;
}
function uc_product_kit_update_3() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_product_kits} ADD COLUMN vid mediumint(9) NOT NULL default 0 FIRST");
      $ret[] = update_sql("ALTER TABLE {uc_product_kits} DROP PRIMARY KEY");
      $result = db_query("SELECT nid, vid FROM {node}");
      while ($product = db_fetch_object($result)) {
        db_query("UPDATE {uc_product_kits} SET vid = %d WHERE nid = %d", $product->vid, $product->nid);
      }
      $ret[] = update_sql("ALTER TABLE {uc_product_kits} ADD PRIMARY KEY (vid, product_id)");
      break;
    case 'pgsql':
      db_add_column($ret, 'uc_product_kits', 'vid', 'mediumint', array(
        'not null' => true,
        'default' => 0,
      ));
      $ret[] = update_sql("ALTER TABLE {uc_product_kits} DROP CONSTRAINT {uc_products}_pkey");
      $result = db_query("SELECT nid, vid FROM {node}");
      while ($product = db_fetch_object($result)) {
        db_query("UPDATE {uc_product_kits} SET vid = %d WHERE nid = %d", $product->vid, $product->nid);
      }
      $ret[] = update_sql("ALTER TABLE {uc_product_kits} ADD PRIMARY KEY (vid, product_id)");
      break;
  }
  return $ret;
}
function uc_product_kit_update_4() {
  $ret = array();
  db_query("UPDATE {node} SET type = 'product_kit' WHERE type = 'kit'");
  if (module_exists('content')) {
    $ret[] = update_sql("ALTER TABLE {content_type_kit} RENAME TO {content_type_product_kit}");
  }
  node_types_rebuild();
  menu_rebuild();
  return $ret;
}
function uc_product_kit_update_5() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_product_kits} DROP data");
      break;
    case 'pgsql':
      $ret[] = update_sql("ALTER TABLE {uc_product_kits} DROP data");
      break;
  }
  return $ret;
}