View source
<?php
function uc_attribute_install() {
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
db_query("CREATE TABLE {uc_attributes} (\n `aid` mediumint(9) NOT NULL auto_increment,\n `name` varchar(255) NOT NULL,\n `ordering` tinyint(2) NOT NULL default 0,\n `required` tinyint(2) NOT NULL default 0,\n `display` tinyint(2) NOT NULL default 1,\n `description` varchar(255) NOT NULL,\n PRIMARY KEY (`aid`)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ;");
db_query("CREATE TABLE {uc_attribute_options} (\n `aid` mediumint(9) NOT NULL,\n `oid` mediumint(9) NOT NULL auto_increment,\n `name` varchar(255) NOT NULL,\n `cost` decimal(10,2) NOT NULL,\n `price` decimal(10,2) NOT NULL,\n `weight` float NOT NULL,\n `ordering` tinyint(2) NOT NULL default 0,\n PRIMARY KEY (`oid`)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ;");
db_query("CREATE TABLE {uc_class_attributes} (\n `pcid` varchar(32) NOT NULL,\n `aid` mediumint(9) NOT NULL,\n `ordering` tinyint(2) NOT NULL default 0,\n `default_option` mediumint(9) NOT NULL default '0',\n `required` tinyint(2) NOT NULL default 0,\n `display` tinyint(2) NOT NULL default 1,\n PRIMARY KEY (`pcid`, `aid`)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ;");
db_query("CREATE TABLE {uc_class_attribute_options} (\n `pcid` varchar(32) NOT NULL,\n `oid` mediumint(9) NOT NULL,\n `cost` decimal(10,2) NOT NULL,\n `price` decimal(10,2) NOT NULL,\n `weight` float NOT NULL,\n `ordering` tinyint(2) NOT NULL default 0,\n PRIMARY KEY (`pcid`,`oid`)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ;");
db_query("CREATE TABLE {uc_product_attributes} (\n `nid` mediumint(9) NOT NULL,\n `aid` mediumint(9) NOT NULL,\n `ordering` tinyint(2) NOT NULL default 0,\n `default_option` mediumint(9) NOT NULL default '0',\n `required` tinyint(2) NOT NULL default 0,\n `display` tinyint(2) NOT NULL default 1,\n PRIMARY KEY (`nid`, `aid`)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ;");
db_query("CREATE TABLE {uc_product_options} (\n `nid` mediumint(9) NOT NULL,\n `oid` mediumint(9) NOT NULL,\n `cost` decimal(10,2) NOT NULL,\n `price` decimal(10,2) NOT NULL,\n `weight` float NOT NULL,\n `ordering` tinyint(2) NOT NULL default 0,\n PRIMARY KEY (`nid`,`oid`)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ;");
db_query("CREATE TABLE {uc_product_adjustments} (\n `nid` mediumint(9) NOT NULL,\n `combination` varchar(255) NOT NULL,\n `model` varchar(255) NOT NULL,\n PRIMARY KEY (`nid`, `combination`)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ;");
break;
case 'pgsql':
db_query("CREATE TABLE {uc_attributes} (\n aid serial NOT NULL,\n name varchar(255) NOT NULL default '',\n ordering smallint NOT NULL default 0,\n required smallint NOT NULL default 0,\n display smallint NOT NULL default 1,\n description varchar(255) NOT NULL default '',\n PRIMARY KEY (aid)\n );");
db_query("CREATE TABLE {uc_attribute_options} (\n aid integer NOT NULL default 0,\n oid serial NOT NULL,\n name varchar(255) NOT NULL default '',\n cost decimal(10,2) NOT NULL default 0.00,\n price decimal(10,2) NOT NULL default 0.00,\n weight float NOT NULL default 0.0,\n ordering smallint NOT NULL default 0,\n PRIMARY KEY (oid)\n ) WITHOUT OIDS;");
db_query("CREATE TABLE {uc_class_attributes} (\n pcid varchar(32) NOT NULL default '',\n aid integer NOT NULL default 0,\n ordering smallint NOT NULL default 0,\n default_option integer NOT NULL default '0',\n required smallint NOT NULL default 0,\n display smallint NOT NULL default 1,\n PRIMARY KEY (pcid, aid)\n );");
db_query("CREATE TABLE {uc_class_attribute_options} (\n pcid varchar(32) NOT NULL default '',\n oid integer NOT NULL default 0,\n cost decimal(10,2) NOT NULL default 0.00,\n price decimal(10,2) NOT NULL default 0.00,\n weight float NOT NULL default 0.0,\n ordering smallint NOT NULL default 0,\n PRIMARY KEY (pcid,oid)\n ) WITHOUT OIDS;");
db_query("CREATE TABLE {uc_product_attributes} (\n nid integer NOT NULL default 0,\n aid integer NOT NULL default 0,\n ordering smallint NOT NULL default 0,\n default_option integer NOT NULL default 0,\n required smallint NOT NULL default 0,\n display smallint NOT NULL default 1,\n PRIMARY KEY (nid, aid)\n );");
db_query("CREATE TABLE {uc_product_options} (\n nid integer NOT NULL default 0,\n oid integer NOT NULL default 0,\n cost decimal(10,2) NOT NULL default 0.00,\n price decimal(10,2) NOT NULL default 0.00,\n weight float NOT NULL default 0,\n ordering smallint NOT NULL default 0,\n PRIMARY KEY (nid,oid)\n ) WITHOUT OIDS;");
db_query("CREATE TABLE {uc_product_adjustments} (\n nid integer NOT NULL default 0,\n combination varchar(255) NOT NULL default '',\n model varchar(255) NOT NULL default '',\n PRIMARY KEY (nid, combination)\n );");
break;
}
}
function uc_attribute_uninstall() {
db_query("DROP TABLE {uc_attributes}");
db_query("DROP TABLE {uc_attribute_options}");
db_query("DROP TABLE {uc_class_attributes}");
db_query("DROP TABLE {uc_class_attribute_options}");
db_query("DROP TABLE {uc_product_attributes}");
db_query("DROP TABLE {uc_product_options}");
db_query("DROP TABLE {uc_product_adjustments}");
variable_del('uc_attribute_option_price_format');
}
function uc_attribute_update_1() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {uc_attributes} CHANGE name name varchar(255) NOT NULL");
$ret[] = update_sql("ALTER TABLE {uc_attributes_options} CHANGE name name varchar(255) NOT NULL");
$ret[] = update_sql("RENAME TABLE {uc_attributes_options} TO {uc_attribute_options}");
$ret[] = update_sql("ALTER TABLE {uc_product_adjustments} CHANGE model model varchar(255) NOT NULL");
$ret[] = update_sql("CREATE TABLE IF NOT EXISTS {uc_class_attributes} (\n `pcid` mediumint(9) NOT NULL,\n `aid` mediumint(9) NOT NULL,\n `default_option` mediumint(9) NOT NULL default '0',\n PRIMARY KEY (`pcid`, `aid`)\n );");
$ret[] = update_sql("CREATE TABLE IF NOT EXISTS {uc_class_attribute_options} (\n `pcid` mediumint(9) NOT NULL,\n `oid` mediumint(9) NOT NULL,\n `price` decimal(10,2) NOT NULL,\n `weight` float NOT NULL,\n PRIMARY KEY (`pcid`,`oid`)\n );");
break;
case 'pgsql':
db_change_column($ret, 'uc_attributes', 'name', 'name', 'varchar(255)', array(
'not null' => true,
'default' => "''",
));
db_change_column($ret, 'uc_attributes_options', 'name', 'name', 'varchar(255)', array(
'not null' => true,
'default' => "''",
));
$ret[] = update_sql("ALTER TABLE {uc_attributes_options} RENAME TO {uc_attribute_options}");
db_change_column($ret, 'uc_product_adjustments', 'model', 'model', 'varchar(255)', array(
'not null' => true,
'default' => "''",
));
$ret[] = update_sql("CREATE TABLE IF NOT EXISTS {uc_class_attributes} (\n pcid integer NOT NULL default '0',\n aid integer NOT NULL '0',\n default_option integer NOT NULL default '0',\n PRIMARY KEY (pcid, aid)\n );");
$ret[] = update_sql("CREATE TABLE IF NOT EXISTS {uc_class_attribute_options} (\n pcid integer NOT NULL default '0',\n oid integer NOT NULL default '0',\n price decimal(10,2) NOT NULL,\n weight float NOT NULL,\n PRIMARY KEY (pcid,oid)\n );");
break;
}
return $ret;
}
function uc_attribute_update_2() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {uc_attributes} ADD COLUMN ordering tinyint(2) NOT NULL default 0 AFTER name");
$ret[] = update_sql("ALTER TABLE {uc_attribute_options} ADD COLUMN ordering tinyint(2) NOT NULL default 0 AFTER weight");
$ret[] = update_sql("ALTER TABLE {uc_class_attributes} ADD COLUMN ordering tinyint(2) NOT NULL default 0 AFTER aid");
$ret[] = update_sql("ALTER TABLE {uc_class_attribute_options} ADD COLUMN ordering tinyint(2) NOT NULL default 0 AFTER weight");
$ret[] = update_sql("ALTER TABLE {uc_product_attributes} ADD COLUMN ordering tinyint(2) NOT NULL default 0 AFTER aid");
$ret[] = update_sql("ALTER TABLE {uc_product_options} ADD COLUMN ordering tinyint(2) NOT NULL default 0 AFTER weight");
break;
case 'pgsql':
db_add_column($ret, 'uc_attributes', 'ordering', 'smallint', array(
'not null' => true,
'default' => 0,
));
db_add_column($ret, 'uc_attribute_options', 'ordering', 'smallint', array(
'not null' => true,
'default' => 0,
));
db_add_column($ret, 'uc_class_attributes', 'ordering', 'smallint', array(
'not null' => true,
'default' => 0,
));
db_add_column($ret, 'uc_class_attribute_options', 'ordering', 'smallint', array(
'not null' => true,
'default' => 0,
));
db_add_column($ret, 'uc_product_attributes', 'ordering', 'smallint', array(
'not null' => true,
'default' => 0,
));
db_add_column($ret, 'uc_product_options', 'ordering', 'smallint', array(
'not null' => true,
'default' => 0,
));
}
return $ret;
}
function uc_attribute_update_3() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {uc_class_attributes} CHANGE pcid pcid varchar(32) NOT NULL");
$ret[] = update_sql("ALTER TABLE {uc_class_attribute_options} CHANGE pcid pcid varchar(32) NOT NULL");
break;
case 'pgsql':
db_change_column($ret, 'uc_class_attributes', 'pcid', 'pcid', 'varchar(32)', array(
'not null' => true,
'default' => "''",
));
db_change_column($ret, 'uc_class_attribute_options', 'pcid', 'pcid', 'varchar(32)', array(
'not null' => true,
'default' => "''",
));
break;
}
return $ret;
}
function uc_attribute_update_4() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {uc_product_adjustments} CHANGE combination combination varchar(255) NOT NULL");
$ret[] = update_sql("ALTER TABLE {uc_product_adjustments} ADD PRIMARY KEY (`nid`, `combination`)");
break;
case 'pgsql':
db_change_column($ret, 'uc_product_adjustments', 'combination', 'combination', 'varchar(255)', array(
'not null' => true,
'default' => "''",
));
$ret[] = update_sql("ALTER TABLE {uc_product_adjustments} ADD PRIMARY KEY (nid, combiination)");
}
return $ret;
}
function uc_attribute_update_5() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {uc_attribute_options} ADD COLUMN cost decimal(10,2) NOT NULL AFTER name");
$ret[] = update_sql("ALTER TABLE {uc_class_attribute_options} ADD COLUMN cost decimal(10,2) NOT NULL AFTER oid");
$ret[] = update_sql("ALTER TABLE {uc_product_options} ADD COLUMN cost decimal(10,2) NOT NULL AFTER oid");
break;
case 'pgsql':
db_add_column($ret, 'uc_attribute_options', 'cost', 'decimal(10,2)', array(
'not null' => true,
'default' => 0.0,
));
db_add_column($ret, 'uc_class_attribute_options', 'cost', 'decimal(10,2)', array(
'not null' => true,
'default' => 0.0,
));
db_add_column($ret, 'uc_product_options', 'cost', 'decimal(10,2)', array(
'not null' => true,
'default' => 0.0,
));
break;
}
return $ret;
}
function uc_attribute_update_6() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {uc_product_attributes} ADD COLUMN required tinyint(2) NOT NULL default 0 AFTER default_option");
break;
case 'pgsql':
db_add_column($ret, 'uc_product_attributes', 'required', 'smallint', array(
'not null' => true,
'default' => 0,
));
break;
}
return $ret;
}
function uc_attribute_update_7() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {uc_class_attributes} ADD COLUMN required tinyint(2) NOT NULL default 0 AFTER default_option");
break;
case 'pgsql':
db_add_column($ret, 'uc_class_attributes', 'required', 'smallint', array(
'not null' => true,
'default' => 0,
));
break;
}
return $ret;
}
function uc_attribute_update_8() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {uc_attribute_options} SET WITHOUT OIDS");
$ret[] = update_sql("ALTER TABLE {uc_class_attribute_options} SET WITHOUT OIDS");
$ret[] = update_sql("ALTER TABLE {uc_product_options} SET WITHOUT OIDS");
break;
}
return $ret;
}
function uc_attribute_update_9() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {uc_attributes} ADD COLUMN required tinyint(2) NOT NULL default 1");
$ret[] = update_sql("ALTER TABLE {uc_attributes} ADD COLUMN display tinyint(2) NOT NULL default 1");
$ret[] = update_sql("ALTER TABLE {uc_class_attributes} ADD COLUMN display tinyint(2) NOT NULL default 1");
$ret[] = update_sql("ALTER TABLE {uc_product_attributes} ADD COLUMN display tinyint(2) NOT NULL default 1");
break;
case 'pgsql':
db_add_column($ret, 'uc_attributes', 'required', 'smallint', array(
'not null' => true,
'default' => 1,
));
db_add_column($ret, 'uc_attributes', 'display', 'smallint', array(
'not null' => true,
'default' => 1,
));
db_add_column($ret, 'uc_class_attributes', 'display', 'smallint', array(
'not null' => true,
'default' => 1,
));
db_add_column($ret, 'uc_product_attributes', 'display', 'smallint', array(
'not null' => true,
'default' => 1,
));
break;
}
return $ret;
}
function uc_attribute_update_10() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {uc_attributes} ADD COLUMN description varchar(255) NOT NULL");
break;
case 'pgsql':
db_add_column($ret, 'uc_attributes', 'description', 'varchar(255)', array(
'not null' => true,
'default' => "''",
));
break;
}
return $ret;
}