View source
<?php
function userpoints_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {userpoints} (\n pid INT(11) NOT NULL AUTO_INCREMENT,\n uid INT(10) NOT NULL DEFAULT '0',\n points INT(10) NOT NULL DEFAULT '0',\n max_points INT(10) NOT NULL DEFAULT '0',\n last_update INT(11) NOT NULL DEFAULT '0',\n tid INT(11) NOT NULL default '0',\n PRIMARY KEY (pid),\n KEY (last_update),\n KEY (uid, tid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("CREATE TABLE {userpoints_txn} (\n txn_id INT NOT NULL AUTO_INCREMENT,\n uid INT(10) NOT NULL DEFAULT '0',\n approver_uid INT(10) NOT NULL DEFAULT '0',\n points INT(10) NOT NULL DEFAULT '0',\n time_stamp INT(11) NOT NULL DEFAULT '0',\n status INT(1) NOT NULL DEFAULT '0',\n expirydate INT(11) NULL DEFAULT '0',\n expired TINYINT(1) NOT NULL DEFAULT '0',\n parent_txn_id INT(11) NOT NULL DEFAULT '0',\n tid INT(11) NOT NULL DEFAULT '0',\n entity_id INT(11) NULL DEFAULT NULL, \n entity_type VARCHAR(32) DEFAULT NULL, \n operation VARCHAR(32),\n reference VARCHAR(128),\n description TEXT,\n PRIMARY KEY (txn_id),\n KEY (status),\n KEY (operation),\n KEY (reference)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
db_query("CREATE TABLE {userpoints} (\n pid INTEGER NOT NULL auto_increment,\n uid SERIAL,\n\t points INTEGER NOT NULL default '0',\n\t max_points INTEGER NOT NULL default '0',\n\t last_update INTEGER NOT NULL default '0',\n tid INTEGER NOT NULL default '0',\n\t PRIMARY KEY (pid),\n\t KEY (last_update),\n KEY (uid, tid)\n );");
db_query("CREATE TABLE {userpoints_txn} (\n txn_id SERIAL,\n\t uid INTEGER NOT NULL default '0',\n\t approver_uid INTEGER NOT NULL default '0',\n\t points INTEGER NOT NULL default '0',\n\t time_stamp INTEGER NOT NULL default '0',\n\t status INTEGER NOT NULL default '0',\n expirydate INTEGER NOT NULL default '0',\n expired BOOLEAN, \n parent_txn_id INTEGER NOT NULL default '0'\n tid INTEGER NOT NULL DEFAULT '0',\n entity_id INTEGER NULL DEFAULT NULL, \n entity_type VARCHAR DEFAULT NULL, \n operation VARCHAR,\n reference VARCHAR,\n description VARCHAR,\n\t PRIMARY KEY (txn_id),\n KEY (status),\n KEY (operation),\n KEY (reference)\n\t );");
break;
}
}
function userpoints_uninstall() {
$vid = db_result(db_query("SELECT vid FROM {vocabulary} WHERE module='userpoints'"));
if ($vid) {
taxonomy_del_vocabulary($vid);
}
db_query('DROP TABLE {userpoints}');
db_query('DROP TABLE {userpoints_txn}');
db_query("DELETE FROM {variable} WHERE name like '%userpoints%'");
}
function userpoints_update_1() {
return _system_update_utf8(array(
'userpoints',
));
}
function userpoints_update_2() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {userpoints} ADD COLUMN max_points INT(10) NOT NULL DEFAULT '0' AFTER points");
$ret[] = update_sql("ALTER TABLE {userpoints} CHANGE points points INT(10) NOT NULL DEFAULT '0'");
break;
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {userpoints} ADD COLUMN max_points INT(10) SET NOT NULL DEFAULT '0' AFTER points");
$ret[] = update_sql("ALTER TABLE {userpoints} ALTER COLUMN points TYPE INT(10) SET NOT NULL DEFAULT '0'");
}
return $ret;
}
function userpoints_update_3() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {userpoints_txn} ADD COLUMN description TEXT AFTER event");
break;
}
return $ret;
}
function userpoints_update_4() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {userpoints_txn} CHANGE event event VARCHAR(32)");
$ret[] = update_sql("ALTER TABLE {userpoints_txn} CHANGE status status INTEGER NOT NULL DEFAULT '0' AFTER time_stamp");
break;
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {userpoints_txn} ALTER COLUMN event TYPE VARCHAR(32)");
$ret[] = update_sql("ALTER TABLE {userpoints_txn} ALTER COLUMN status TYPE INTEGER SET NOT NULL DEFAULT '0' AFTER time_stamp");
}
return $ret;
}
function userpoints_update_5() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {userpoints_txn} ADD COLUMN reference VARCHAR(128) AFTER description");
$ret[] = update_sql("ALTER TABLE {userpoints_txn} ADD INDEX reference (reference )");
break;
}
return $ret;
}
function userpoints_update_6() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {userpoints} ADD COLUMN tid INT NULL AFTER last_update");
$ret[] = update_sql("ALTER TABLE {userpoints} DROP PRIMARY KEY");
$ret[] = update_sql("ALTER TABLE {userpoints} ADD COLUMN pid INT NOT NULL AUTO_INCREMENT PRIMARY KEY");
$ret[] = update_sql("ALTER TABLE {userpoints_txn} ADD COLUMN expirydate INT(11) NOT NULL AFTER reference");
$ret[] = update_sql("ALTER TABLE {userpoints_txn} ADD COLUMN expired TINYINT(1) NOT NULL AFTER expirydate");
$ret[] = update_sql("ALTER TABLE {userpoints_txn} ADD COLUMN parent_txn_id INT NOT NULL AFTER expired");
$ret[] = update_sql("ALTER TABLE {userpoints_txn} ADD COLUMN tid INT NULL AFTER parent_txn_id");
break;
}
return $ret;
}
function userpoints_update_7() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {userpoints_txn} ADD COLUMN entity_id INT(11) NULL AFTER tid");
$ret[] = update_sql("ALTER TABLE {userpoints_txn} ADD COLUMN entity_type VARCHAR(32) NULL AFTER entity_id");
$ret[] = update_sql("ALTER TABLE {userpoints_txn} CHANGE event operation VARCHAR(32)");
break;
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {userpoints_txn} ADD COLUMN entity_id INT(11) NULL AFTER tid");
$ret[] = update_sql("ALTER TABLE {userpoints_txn} ADD COLUMN entity_type VARCHAR(32) NULL AFTER entity_id");
$ret[] = update_sql("ALTER TABLE {userpoints_txn} RENAME event TO operation VARCHAR(32)");
break;
}
return $ret;
}
function userpoints_update_8() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {userpoints_txn} CHANGE tid tid INT(11) NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE {userpoints} CHANGE tid tid INT(11) NOT NULL default '0'");
break;
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {userpoints_txn} ALTER COLUMN tid TYPE INT(11) SET NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE {userpoints} ALTER COLUMN tid TYPE INT(11) SET NOT NULL default '0'");
break;
}
return $ret;
}
function userpoints_update_5009() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {userpoints} DROP INDEX tid");
$ret[] = update_sql("ALTER TABLE {userpoints} ADD INDEX uid_tid (uid, tid)");
break;
}
return $ret;
}