You are here

uc_roles.install in Ubercart 5

Same filename and directory in other branches
  1. 6.2 uc_roles/uc_roles.install
  2. 7.3 uc_roles/uc_roles.install

File

uc_roles/uc_roles.install
View source
<?php

function uc_roles_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      db_query("CREATE TABLE {uc_roles_products} (\n        pfid mediumint(9) NOT NULL,\n        nid int(10) NOT NULL,\n        model varchar(255) default NULL,\n        rid mediumint(11) NOT NULL,\n        duration smallint(4) default NULL,\n        granularity varchar(32) default NULL,\n        shippable BOOL NOT NULL,\n        by_quantity BOOL NOT NULL,\n        KEY pfid (pfid),\n        KEY nid (nid),\n        KEY model (model),\n        KEY rid (rid)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("CREATE TABLE {uc_roles_expirations} (\n        uid mediumint(11) NOT NULL,\n        rid mediumint(11) NOT NULL,\n        expiration int(11) NOT NULL,\n        notified tinyint(2) default NULL,\n        KEY uid (uid),\n        KEY rid (rid)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {uc_roles_products} (\n        pfid integer NOT NULL,\n        nid integer NOT NULL,\n        model varchar(255) default NULL,\n        rid integer NOT NULL,\n        duration smallint default NULL,\n        granularity varchar(32) default NULL,\n        shippable boolean NOT NULL,\n        by_quantity boolean NOT NULL\n        );");
      db_query("CREATE INDEX {uc_roles_products}_pfid ON {uc_roles_products} (pfid)");
      db_query("CREATE INDEX {uc_roles_products}_nid ON {uc_roles_products} (nid)");
      db_query("CREATE INDEX {uc_roles_products}_model ON {uc_roles_products} (model)");
      db_query("CREATE INDEX {uc_roles_products}_rid ON {uc_roles_products} (rid)");
      db_query("CREATE TABLE {uc_roles_expirations} (\n        uid integer NOT NULL,\n        rid integer NOT NULL,\n        expiration integer NOT NULL,\n        notified smallint default NULL\n        );");
      db_query("CREATE INDEX {uc_roles_expirations}_uid ON {uc_roles_expirations} (uid)");
      db_query("CREATE INDEX {uc_roles_expirations}_rid ON {uc_roles_expirations} (rid)");
      break;
  }
}
function uc_roles_uninstall() {
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      db_query("DROP TABLE IF EXISTS {uc_roles_products}");
      db_query("DROP TABLE IF EXISTS {uc_roles_expirations}");
      break;
    case 'pgsql':
      db_query("DROP TABLE {uc_roles_products}");
      db_query("DROP TABLE {uc_roles_expirations}");
      break;
  }
  db_query("DELETE FROM {variable} WHERE name LIKE 'uc_roles_%%'");
}
function uc_roles_update_1() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_roles_products} CHANGE expiration duration SMALLINT( 4 ) NULL DEFAULT NULL");
      $ret[] = update_sql("ALTER TABLE {uc_roles_products} CHANGE model model VARCHAR( 255 ) CHARACTER SET utf8 NULL");
      break;
    case 'pgsql':
      break;
  }
  return $ret;
}
function uc_roles_update_2() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_roles_products} ADD shippable BOOL NOT NULL");
      break;
    case 'pgsql':
      break;
  }
  return $ret;
}
function uc_roles_update_3() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_roles_products} ADD by_quantity BOOL NOT NULL");
      break;
    case 'pgsql':
      $ret[] = update_sql("ALTER TABLE {uc_roles_products} ADD by_quantity boolean NOT NULL");
      break;
  }
  return $ret;
}
function uc_roles_update_4() {
  $ret = array();

  // Fixes the db_next_id() + 1 error.
  $pfid = db_result(db_query("SELECT MAX(pfid) FROM {uc_product_features}"));
  $ret[] = update_sql("UPDATE {sequences} SET id = " . intval($pfid) . " WHERE name = '{uc_product_features}_pfid'");
  return $ret;
}