community_tags.install in Community Tags 5
File
community_tags.install
View source
<?php
function community_tags_install() {
$status = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$status[] = db_query("CREATE TABLE {community_tags} (\n tid int(10) unsigned NOT NULL DEFAULT '0',\n nid int(10) unsigned NOT NULL DEFAULT '0',\n uid int(10) unsigned NOT NULL DEFAULT '0',\n date int(10) unsigned NOT NULL DEFAULT '0',\n PRIMARY KEY (tid,nid,uid),\n KEY tid (tid),\n KEY nid (nid),\n KEY uid (uid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
$status[] = db_query("CREATE TABLE {community_tags} (\n tid integer NOT NULL DEFAULT '0',\n nid integer NOT NULL DEFAULT '0',\n uid integer NOT NULL DEFAULT '0',\n date integer NOT NULL DEFAULT '0',\n PRIMARY KEY (tid,nid,uid)\n );");
$status[] = db_query("CREATE INDEX {community_tags}_tid_idx ON {community_tags} (tid);");
$status[] = db_query("CREATE INDEX {community_tags}_nid_idx ON {community_tags} (nid);");
$status[] = db_query("CREATE INDEX {community_tags}_uid_idx ON {community_tags} (uid);");
break;
}
$weight = (int) db_result(db_query("SELECT weight FROM {system} WHERE name = 'taxonomy'"));
db_query("UPDATE {system} SET weight = %d WHERE name = 'community_tags'", $weight + 1);
if (array_search(FALSE, $status) !== FALSE) {
drupal_set_message(t('Table installation for the Community Tags module was unsuccessful. The tables may need to be installed by hand.'), 'error');
}
else {
drupal_set_message(t('Community Tags module installed successfully.'));
}
}
function community_tags_uninstall() {
db_query('DROP TABLE {community_tags}');
}
function community_tags_update_1() {
$items = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$items[] = update_sql('ALTER TABLE {community_tags} ADD KEY tid (tid)');
break;
case 'pgsql':
$items[] = update_sql("CREATE INDEX {community_tags}_tid_idx ON {community_tags} (tid);");
break;
}
community_tags_rehash(TRUE);
return $items;
}
function community_tags_enable() {
community_tags_rehash();
}