View source
<?php
function votingapi_install() {
drupal_install_schema('votingapi');
}
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_update_6001() {
$ret = array();
db_change_field($ret, 'votingapi_vote', 'hostname', 'vote_source', array(
'type' => 'varchar',
'length' => 255,
));
db_update_field($ret, 'votingapi_vote', 'vote_id');
db_update_field($ret, 'votingapi_vote', 'content_type');
db_update_field($ret, 'votingapi_vote', 'content_id');
db_update_field($ret, 'votingapi_vote', 'value');
db_update_field($ret, 'votingapi_vote', 'value_type');
db_update_field($ret, 'votingapi_vote', 'tag');
db_update_field($ret, 'votingapi_vote', 'uid');
db_update_field($ret, 'votingapi_vote', 'timestamp');
db_update_field($ret, 'votingapi_vote', 'vote_source');
db_update_field($ret, 'votingapi_cache', 'vote_cache_id');
db_update_field($ret, 'votingapi_cache', 'content_type');
db_update_field($ret, 'votingapi_cache', 'content_id');
db_update_field($ret, 'votingapi_cache', 'value');
db_update_field($ret, 'votingapi_cache', 'value_type');
db_update_field($ret, 'votingapi_cache', 'tag');
db_update_field($ret, 'votingapi_cache', 'function');
db_update_field($ret, 'votingapi_cache', 'timestamp');
return $ret;
}
function votingapi_uninstall() {
db_query("DROP TABLE {votingapi_vote}");
db_query("DROP TABLE {votingapi_cache}");
}