You are here

uc_file.install in Ubercart 5

File

uc_file/uc_file.install
View source
<?php

function uc_file_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      db_query("CREATE TABLE {uc_files} (\n        `fid` mediumint(9) NOT NULL,\n        `filename` varchar(255) NOT NULL,\n        KEY fid (fid)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("CREATE TABLE {uc_file_products} (\n        `pfid` mediumint(9) NOT NULL,\n        `fid` mediumint(9) NOT NULL,\n        `model` varchar(255) default NULL,\n        `description` VARCHAR(255) default NULL,\n        `shippable` BOOL NOT NULL,\n        KEY pfid (pfid),\n        KEY fid (fid)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("CREATE TABLE {uc_file_users} (\n        `fid` mediumint(9) NOT NULL,\n        `uid` mediumint(9) NOT NULL,\n        `pfid` mediumint(9) default NULL,\n        `file_key` varchar(32) NOT NULL,\n        `granted` int(11) NOT NULL,\n        `accessed` smallint(5) unsigned NOT NULL default 0,\n        `addresses` text,\n        KEY fid (fid),\n        KEY uid (uid)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {uc_files} (\n        fid serial NOT NULL,\n        filename varchar(255) NOT NULL,\n        PRIMARY KEY (fid)\n        );");
      db_query("CREATE INDEX {uc_files}_fid ON {uc_files} (fid)");
      db_query("CREATE TABLE {uc_file_products} (\n        pfid integer NOT NULL,\n        fid integer NOT NULL,\n        model varchar(255) default NULL,\n        description varchar(255) default NULL,\n        shippable boolean NOT NULL\n        );");
      db_query("CREATE INDEX {uc_file_products}_pfid ON {uc_file_products} (pfid)");
      db_query("CREATE INDEX {uc_file_products}_fid ON {uc_file_products} (fid)");
      db_query("CREATE TABLE {uc_file_users} (\n        fid integer NOT NULL,\n        uid integer NOT NULL,\n        pfid integer default NULL,\n        key varchar(32) NOT NULL,\n        granted integer NOT NULL,\n        accessed smallint_unsigned NOT NULL default 0,\n        addresses text\n        );");
      db_query("CREATE INDEX {uc_file_users}_pfid ON {uc_file_users} (pfid)");
      db_query("CREATE INDEX {uc_file_users}_uid ON {uc_file_users} (uid)");
      break;
  }
}
function uc_file_uninstall() {
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      db_query("DROP TABLE IF EXISTS {uc_files}");
      db_query("DROP TABLE IF EXISTS {uc_file_products}");
      db_query("DROP TABLE IF EXISTS {uc_file_users}");
      db_query("DELETE FROM {uc_product_features} WHERE fid = 'file'");
      break;
    case 'pgsql':
      db_query("DROP TABLE {uc_files}");
      db_query("DROP TABLE {uc_file_products}");
      db_query("DROP TABLE {uc_file_users}");
      db_query("DELETE FROM {uc_product_features} WHERE fid = 'file'");
      break;
  }
}
function uc_file_update_1() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {uc_file_products} ADD `description` VARCHAR( 255 ) NULL AFTER `model`");
      $ret[] = update_sql("ALTER TABLE {uc_file_users} CHANGE model `pfid` mediumint(9) NULL DEFAULT NULL");
      break;
    case 'pgsql':
      break;
  }
  return $ret;
}
function uc_file_update_2() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'pgsql':
      db_change_column($ret, 'uc_file_users', 'accessed', 'accessed', 'smallint_unsigned', array(
        'not null' => true,
        'default' => 0,
      ));
      break;
  }
  return $ret;
}
function uc_file_update_3() {
  $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;
}
function uc_file_update_4() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql("ALTER TABLE {uc_file_users} CHANGE `key` `file_key` VARCHAR(32) NOT NULL");
      break;
    case 'pgsql':
      db_change_column($ret, 'uc_file_users', 'key', 'file_key', 'varchar(32)', array(
        'not null' => TRUE,
      ));
      break;
  }
  return $ret;
}