View source
<?php
function _user_relationships_installation_query($mysql = array(), $pgsql = array()) {
global $db_type;
$success = TRUE;
$queries = array();
if (strpos('mysql', $db_type) !== FALSE && $mysql) {
$queries = $mysql;
}
else {
if ($db_type == 'pgsql' && $pgsql) {
$queries = $pgsql;
}
else {
$success = FALSE;
drupal_set_message(t('Unsupported database.'));
}
}
foreach ($queries as $query) {
if (!db_query($query)) {
$success = FALSE;
break;
}
}
if ($success) {
drupal_set_message(t('User Relationships module installed successfully.'));
}
else {
drupal_set_message(t('The installation of the User Relationships module was unsuccessful.'), 'error');
}
}
function user_relationships_install() {
$queries = array(
"CREATE TABLE {user_relationship_types} (\n rtid int unsigned NOT NULL default 0,\n name varchar(255) NOT NULL default '',\n plural_name varchar(255) NOT NULL default '',\n is_oneway tinyint(1) NOT NULL default 0,\n requires_approval tinyint(1) NOT NULL default 0,\n expires_val int unsigned NOT NULL default 0,\n PRIMARY KEY (rtid),\n UNIQUE KEY name (name)\n ) /*!40100 DEFAULT CHARACTER SET utf8*/;",
"CREATE TABLE {user_relationships} (\n rid int unsigned NOT NULL default 0,\n requester_id int NOT NULL default 0,\n requestee_id int NOT NULL default 0,\n rtid int NOT NULL default 0,\n approved tinyint(1) NOT NULL default 0,\n created_at datetime NOT NULL,\n updated_at timestamp NOT NULL,\n PRIMARY KEY (rid),\n KEY requester_id (requester_id),\n KEY requestee_id (requestee_id),\n KEY rtid (rtid)\n ) /*!40100 DEFAULT CHARACTER SET utf8*/;",
"CREATE TABLE {cache_user_relationships} (\n cid varchar(255) NOT NULL default '',\n data longblob,\n expire int(11) NOT NULL default 0,\n created int(11) NOT NULL default 0,\n headers text,\n serialized int(1) NOT NULL default 0,\n PRIMARY KEY (cid),\n KEY expire (expire)\n ) /*!40100 DEFAULT CHARACTER SET utf8*/;",
);
_user_relationships_installation_query($queries);
}
function user_relationships_uninstall() {
db_query('DROP TABLE {user_relationships}');
db_query('DROP TABLE {user_relationship_types}');
db_query('DROP TABLE {cache_user_relationships}');
variable_del('user_relationships_require_approval');
variable_del('user_relationships_allow_multiple');
variable_del('user_relationships_show_online_status');
variable_del('user_relationships_user_mail');
variable_del('user_relationships_profile_relationships');
}
function user_relationships_update_1() {
$queries = array(
"ALTER TABLE {user_relationships} ADD created_at DATETIME NOT NULL;",
"ALTER TABLE {user_relationships} ADD updated_at TIMESTAMP NOT NULL;",
"UPDATE {user_relationships} SET created_at = NOW();",
);
_user_relationships_installation_query($queries);
}
function user_relationships_update_2() {
_user_relationships_installation_query(array(
"ALTER TABLE {user_relationship_types} ADD expires_val int(11) unsigned NOT NULL default 0;",
));
}
function user_relationships_update_3() {
_user_relationships_installation_query(array(
"ALTER TABLE {user_relationship_types} ADD plural_name varchar(255) NOT NULL default '' after name;",
));
}
function user_relationships_update_4() {
_user_relationships_installation_query(array(
"CREATE TABLE {cache_user_relationships} (\n cid varchar(255) NOT NULL default '',\n data longblob,\n expire int(11) NOT NULL default 0,\n created int(11) NOT NULL default 0,\n headers text,\n serialized int(1) NOT NULL default 0,\n PRIMARY KEY (cid),\n KEY expire (expire)\n ) /*!40100 DEFAULT CHARACTER SET utf8*/;",
));
}