uc_coupon.install in Ubercart Discount Coupons 5
Same filename and directory in other branches
Ubercart uc_coupon.module schema
File
uc_coupon.installView source
<?php
/**
* @file
* Ubercart uc_coupon.module schema
*/
function uc_coupon_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {uc_coupons} (\n cid int(11) NOT NULL auto_increment,\n name varchar(30) NOT NULL,\n code varchar(40) NOT NULL,\n value decimal(6,2) NOT NULL,\n type varchar(12) NOT NULL default 'price',\n status int(1) NOT NULL default '1',\n valid_from int(11) default NULL,\n valid_until int(11) default NULL,\n max_uses int(4) NOT NULL,\n minimum_order decimal(6,2) NOT NULL default 0.00,\n data text,\n bulk int(1) NOT NULL default 0,\n bulk_seed char(32) NOT NULL,\n PRIMARY KEY (cid)\n )");
db_query("CREATE TABLE {uc_coupons_orders} (\n cuid int(11) NOT NULL auto_increment,\n cid int(11) NOT NULL,\n oid int(11) NOT NULL,\n value decimal(10,2) NOT NULL,\n code varchar(40) NOT NULL,\n PRIMARY KEY (cuid)\n )");
break;
}
}
function uc_coupon_uninstall() {
db_query("DROP TABLE {uc_coupons}");
db_query("DROP TABLE {uc_coupons_orders}");
}
function uc_coupon_update_1() {
$ret[] = update_sql("ALTER TABLE {uc_coupons} ADD COLUMN products varchar(50) NOT NULL AFTER max_uses");
return $ret;
}
function uc_coupon_update_2() {
$ret[] = update_sql("ALTER TABLE {uc_coupons} ADD COLUMN data text");
$result = db_query('SELECT cid, products, users FROM {uc_coupons}');
while ($row = db_fetch_object($result)) {
$data = array();
if ($row->products) {
$data['products'] = explode(',', $row->products);
}
if ($row->users) {
// substr() removes the final comma that was present in the previous strings.
$data['users'] = explode(',', substr($row->users, 0, -1));
}
db_query("UPDATE {uc_coupons} SET data = '%s' WHERE cid = %d", serialize($data), $row->cid);
}
$ret[] = update_sql("ALTER TABLE {uc_coupons} DROP COLUMN products");
$ret[] = update_sql("ALTER TABLE {uc_coupons} DROP COLUMN users");
// These columns were never used.
$ret[] = update_sql("ALTER TABLE {uc_coupons_orders} DROP COLUMN user");
$ret[] = update_sql("ALTER TABLE {uc_coupons_orders} DROP COLUMN role");
return $ret;
}
function uc_coupon_update_3() {
$result = db_query('SELECT cid, data, roles FROM {uc_coupons}');
while ($row = db_fetch_object($result)) {
$data = $row->data ? unserialize($row->data) : array();
$data['wholesale'] = $row->roles;
db_query("UPDATE {uc_coupons} SET data = '%s' WHERE cid = %d", serialize($data), $row->cid);
}
$ret[] = update_sql("ALTER TABLE {uc_coupons} DROP COLUMN roles");
return $ret;
}
function uc_coupon_update_4() {
$ret[] = update_sql("ALTER TABLE {uc_coupons} ADD COLUMN bulk int(1) NOT NULL default 0");
$ret[] = update_sql("ALTER TABLE {uc_coupons} ADD COLUMN bulk_seed char(32) NOT NULL");
$ret[] = update_sql("UPDATE {uc_coupons} SET bulk_seed = MD5(RAND()) WHERE bulk_seed = ''");
return $ret;
}
function uc_coupon_update_5() {
$ret[] = update_sql("ALTER TABLE {uc_coupons} ADD COLUMN valid_from int(11) AFTER status");
$ret[] = update_sql("UPDATE {uc_coupons} SET valid_from = 0");
return $ret;
}
Functions
Name | Description |
---|---|
uc_coupon_install | @file Ubercart uc_coupon.module schema |
uc_coupon_uninstall | |
uc_coupon_update_1 | |
uc_coupon_update_2 | |
uc_coupon_update_3 | |
uc_coupon_update_4 | |
uc_coupon_update_5 |