fivestar_comment.install in Fivestar 5
Same filename and directory in other branches
Installation file for Fivestar Comment module.
File
fivestar_comment.installView source
<?php
/**
* @file
* Installation file for Fivestar Comment module.
*/
function fivestar_comment_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {fivestar_comment} (\n cid int NOT NULL default '0',\n vote_id int(10) NOT NULL default '0',\n value tinyint unsigned NOT NULL default '0',\n PRIMARY KEY (cid),\n INDEX (vote_id)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
break;
case 'pgsql':
db_query("CREATE TABLE {fivestar_comment} (\n cid integer NOT NULL default '0',\n vote_id integer NOT NULL default '0',\n value smallint NOT NULL default '0',\n PRIMARY KEY (cid)\n )");
db_query("CREATE INDEX {fivestar_comment}_vote_id_idx ON {fivestar_comment} (vote_id)");
break;
}
}
function fivestar_comment_uninstall() {
db_query("DROP TABLE {fivestar_comment}");
db_query("DELETE FROM {variable} WHERE name LIKE 'fivestar_comment_%'");
}
/**
* Add vote_id column to the fivestar_comment table. This update will only
* be run when upgrading to fivestar schema 5102.
*/
function fivestar_comment_update_5100() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {fivestar_comment} ADD vote_id int(10) UNSIGNED NOT NULL DEFAULT '0' AFTER cid");
$ret[] = update_sql("ALTER TABLE {fivestar_comment} ADD INDEX vote_id (vote_id)");
break;
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {fivestar_comment} ADD vote_id integer NOT NULL DEFAULT '0'");
$ret[] = update_sql("CREATE INDEX {fivestar_comment}_vote_id_idx ON {fivestar_comment} (vote_id)");
break;
}
$comments = db_query('SELECT fc.cid, fc.value, v.vote_id FROM {fivestar_comment} fc INNER JOIN {comments} c ON fc.cid = c.cid INNER JOIN {votingapi_vote} v ON fc.value = v.value AND c.nid = v.content_id AND c.uid = v.uid WHERE v.tag = "vote" AND v.value_type = "percent" AND v.content_type = "node"');
while ($comment = db_fetch_object($comments)) {
db_query('UPDATE {fivestar_comment} SET vote_id = %d WHERE cid = %d', $comment->vote_id, $comment->cid);
}
return $ret;
}
Functions
Name | Description |
---|---|
fivestar_comment_install | @file Installation file for Fivestar Comment module. |
fivestar_comment_uninstall | |
fivestar_comment_update_5100 | Add vote_id column to the fivestar_comment table. This update will only be run when upgrading to fivestar schema 5102. |