View source
<?php
function votingapi_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {votingapi_vote} (\n vote_id int(10) unsigned NOT NULL,\n content_type varchar(20) default NULL,\n content_id int(10) unsigned default NULL,\n value float(10) default NULL,\n value_type varchar(20) NOT NULL,\n tag varchar(128) default 'vote',\n uid int(10) unsigned default '0',\n timestamp int(11) default NULL,\n hostname varchar(128) default '0',\n PRIMARY KEY (vote_id),\n INDEX content (content_type, content_id)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
db_query("CREATE TABLE {votingapi_cache} (\n vote_cache_id int(10) unsigned NOT NULL,\n content_type varchar(20) default NULL,\n content_id int(10) unsigned default NULL,\n value float(10) default NULL,\n value_type varchar(20) NOT NULL,\n tag varchar(128) default 'vote',\n function varchar(128) default 'count',\n timestamp int(11) default NULL,\n PRIMARY KEY (vote_cache_id),\n INDEX content (content_type, content_id)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
db_query("CREATE TABLE {votingapi_vote} (\n vote_id int4 NOT NULL,\n content_type varchar(20) default NULL,\n content_id int4 default NULL,\n value float(10) default NULL,\n value_type varchar(20) NOT NULL,\n tag varchar(128) default 'vote',\n uid int4 default '0',\n timestamp int4 default NULL,\n hostname varchar(128) default '0',\n PRIMARY KEY (vote_id));");
db_query("CREATE SEQUENCE {votingapi_vote}_seq;");
db_query("CREATE INDEX {votingapi_vote}_content_type_id_idx\n ON {votingapi_vote} (content_type, content_id);");
db_query("CREATE TABLE {votingapi_cache} (\n vote_cache_id int4 NOT NULL,\n content_type varchar(20) default NULL,\n content_id int4 default NULL,\n value float(10) default NULL,\n value_type varchar(20) NOT NULL,\n tag varchar(128) default 'vote',\n function varchar(128) default 'count',\n timestamp int4 default NULL,\n PRIMARY KEY (vote_cache_id));");
db_query("CREATE SEQUENCE {votingapi_cache}_seq;");
db_query("CREATE INDEX {votingapi_cache}_content_type_id_idx\n ON {votingapi_cache} (content_type, content_id);");
break;
}
}
function votingapi_update_1() {
return _system_update_utf8(array(
'votingapi_vote',
'votingapi_cache',
));
}
function votingapi_update_2() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {votingapi_cache} CHANGE value value float(10) default NULL");
$ret[] = update_sql("ALTER TABLE {votingapi_vote} CHANGE value value float(10) default NULL");
break;
}
return $ret;
}
function votingapi_update_3() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {votingapi_cache} CHANGE value_type value_type varchar(20) NOT NULL");
$ret[] = update_sql("ALTER TABLE {votingapi_vote} CHANGE value_type value_type varchar(20) NOT NULL");
$ret[] = update_sql("ALTER TABLE {votingapi_cache} ADD INDEX (content_type)");
$ret[] = update_sql("ALTER TABLE {votingapi_cache} ADD INDEX (content_id)");
$ret[] = update_sql("ALTER TABLE {votingapi_vote} ADD INDEX (content_type)");
$ret[] = update_sql("ALTER TABLE {votingapi_vote} ADD INDEX (content_id)");
$ret[] = db_query("UPDATE {votingapi_cache} SET value_type = 'percent' WHERE value_type = '1'");
$ret[] = db_query("UPDATE {votingapi_cache} SET value_type = 'points' WHERE value_type = '2'");
$ret[] = db_query("UPDATE {votingapi_cache} SET value_type = 'option' WHERE value_type = '3'");
$ret[] = db_query("UPDATE {votingapi_vote} SET value_type = 'percent' WHERE value_type = '1'");
$ret[] = db_query("UPDATE {votingapi_vote} SET value_type = 'points' WHERE value_type = '2'");
$ret[] = db_query("UPDATE {votingapi_vote} SET value_type = 'option' WHERE value_type = '3'");
break;
}
return $ret;
}
function votingapi_update_4() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("CREATE TABLE {votingapi_action_set} (\n vasid int(10) unsigned NOT NULL,\n parent int(10) unsigned NOT NULL,\n required int(8) NOT NULL default '0',\n mask varchar(8) default 'AND',\n content_type varchar(20) default NULL,\n name varchar(128) default NULL,\n enabled int default 1,\n source varchar(65) default NULL,\n weight int(10) NOT NULL default 0,\n PRIMARY KEY (vasid)\n ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
$ret[] = update_sql("CREATE TABLE {votingapi_action_condition} (\n vacid int(10) unsigned NOT NULL,\n vasid int(10) unsigned NOT NULL,\n weight int(10) NOT NULL default 0,\n value varchar(255),\n handler varchar(255) NOT NULL,\n PRIMARY KEY (vacid)\n ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
$ret[] = update_sql("CREATE TABLE {votingapi_action} (\n vasid int(10) unsigned NOT NULL,\n aid varchar(255) NOT NULL default '0'\n ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
}
return $ret;
}
function votingapi_update_5() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {votingapi_vote} ADD INDEX content (content_type, content_id);");
$ret[] = update_sql("ALTER TABLE {votingapi_cache} ADD INDEX content (content_type, content_id);");
$ret[] = update_sql("ALTER TABLE {votingapi_vote} DROP INDEX content_type;");
$ret[] = update_sql("ALTER TABLE {votingapi_vote} DROP INDEX content_id;");
$ret[] = update_sql("ALTER TABLE {votingapi_cache} DROP INDEX content_type;");
$ret[] = update_sql("ALTER TABLE {votingapi_cache} DROP INDEX content_id;");
$ret[] = update_sql("RENAME TABLE votingapi_action_condition TO {votingapi_action_condition};");
$ret[] = update_sql("RENAME TABLE votingapi_action TO {votingapi_action};");
$ret[] = update_sql("UPDATE {sequences} SET name = '{votingapi_cache}' WHERE name = 'votingapi_cache';");
$ret[] = update_sql("UPDATE {sequences} SET name = '{votingapi_vote}' WHERE name = 'votingapi_vote';");
break;
}
return $ret;
}
function votingapi_update_6() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {votingapi_action_condition} ADD COLUMN name varchar(128) NOT NULL;");
$ret[] = update_sql("ALTER TABLE {votingapi_action_condition} CHANGE value data varchar(255)");
$ret[] = update_sql("ALTER TABLE {votingapi_action_set} ADD COLUMN description varchar(255) NOT NULL;");
break;
}
return $ret;
}
function votingapi_update_7() {
$ret[] = update_sql("DROP TABLE {votingapi_action_set}");
$ret[] = update_sql("DROP TABLE {votingapi_action_condition}");
$ret[] = update_sql("DROP TABLE {votingapi_action}");
$ret[] = update_sql("CREATE TABLE {votingapi_action_set} (\n name varchar(64) NOT NULL,\n parent_name varchar(64) default NULL,\n content_type varchar(20) default NULL,\n source varchar(64) default NULL,\n description varchar(255) default NULL,\n required int(8) NOT NULL default '0',\n criteria_mask varchar(8) default 'AND',\n weight int(10) NOT NULL default 0,\n PRIMARY KEY (name)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
$ret[] = update_sql("CREATE TABLE {votingapi_action_condition} (\n name varchar(64) NOT NULL,\n parent_name varchar(64) default NULL,\n description varchar(255) default NULL,\n weight int(10) NOT NULL default 0,\n data varchar(255),\n handler varchar(255) NOT NULL,\n PRIMARY KEY (name)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
$ret[] = update_sql("CREATE TABLE {votingapi_action} (\n parent_name varchar(64) NOT NULL,\n aid varchar(255) NOT NULL\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
return $ret;
}
function votingapi_update_8() {
$ret = array();
$ret[] = update_sql("ALTER TABLE {votingapi_action_set} CHANGE criteria_mask condition_mask varchar(8) DEFAULT 'AND';");
return $ret;
}
function votingapi_update_9() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {votingapi_cache} ADD COLUMN timestamp int(11) default NULL;");
break;
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {votingapi_cache} ADD COLUMN timestamp int4 default NULL;");
break;
}
$ret[] = update_sql("UPDATE {votingapi_cache} SET timestamp = " . time() . " WHERE timestamp IS NULL;");
return $ret;
}
function votingapi_uninstall() {
db_query("DROP TABLE {votingapi_vote}");
db_query("DROP TABLE {votingapi_cache}");
}