You are here

user_relationships.install in User Relationships 5

Same filename and directory in other branches
  1. 5.2 user_relationships.install
  2. 7 user_relationships.install

File

user_relationships.install
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);
}

/**
 * Implementation of hook_uninstall().
 */
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');
}

/**
 * Update 1: Add timestamp to allow expiring unanswered requests
 */
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);
}

/**
 * Update 2: Add expiration of relationship requests
 */
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;",
  ));
}

/**
 * Update 3: Add plural form of relationship type name
 */
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;",
  ));
}

/**
 * Update 4: Add separate cache table for user relationship data
 */
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*/;",
  ));
}

Functions

Namesort descending Description
user_relationships_install
user_relationships_uninstall Implementation of hook_uninstall().
user_relationships_update_1 Update 1: Add timestamp to allow expiring unanswered requests
user_relationships_update_2 Update 2: Add expiration of relationship requests
user_relationships_update_3 Update 3: Add plural form of relationship type name
user_relationships_update_4 Update 4: Add separate cache table for user relationship data
_user_relationships_installation_query