You are here

forum_access.install in Forum Access 5

Same filename and directory in other branches
  1. 8 forum_access.install
  2. 6 forum_access.install
  3. 7 forum_access.install

File

forum_access.install
View source
<?php

function forum_access_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE IF NOT EXISTS {forum_access} (\n        tid int(10) NOT NULL default 0,\n        rid int(10) NOT NULL default 0,\n        grant_view tinyint(1) unsigned NOT NULL default '0',\n        grant_update tinyint(1) unsigned NOT NULL default '0',\n        grant_delete tinyint(1) unsigned NOT NULL default '0',\n        grant_create tinyint(1) unsigned NOT NULL default '0',\n        priority smallint NOT NULL default 0,\n        KEY tid (tid),\n        KEY rid (rid)\n      );");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {forum_access} (\n        tid int NOT NULL DEFAULT 0,\n        rid int NOT NULL DEFAULT 0,\n        grant_view smallint NOT NULL DEFAULT 0,\n        grant_update smallint  NOT NULL DEFAULT 0,\n        grant_delete smallint NOT NULL DEFAULT 0,\n        grant_create smallint NOT NULL DEFAULT 0,\n        priority smallint NOT NULL DEFAULT 0,\n        PRIMARY KEY (tid, rid)\n      );");
      break;
  }
  db_query("UPDATE {system} SET weight = 2 WHERE name = 'forum_access'");
}
function forum_access_uninstall() {
  db_query("DROP TABLE {forum_access}");
}

/**
 * Purge orphaned grants that were left behind when deleting roles.
 */
function forum_access_update_1() {
  $ret = array();
  db_query("DELETE FROM {forum_access} WHERE rid NOT IN (SELECT rid from {role})");
  db_query("DELETE FROM {node_access} WHERE realm = 'forum_access' AND gid NOT IN (SELECT rid from {role})");
  return $ret;
}

/**
 * Add a priority column (will probably not be used until D6).
 */
function forum_access_update_2() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'pgsql':
      db_add_column($ret, 'forum_access', 'priority', 'smallint', array(
        'not null' => TRUE,
        'default' => 0,
      ));
      break;
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {forum_access} ADD COLUMN priority smallint NOT NULL DEFAULT 0");
      break;
  }
  return $ret;
}

Functions

Namesort descending Description
forum_access_install
forum_access_uninstall
forum_access_update_1 Purge orphaned grants that were left behind when deleting roles.
forum_access_update_2 Add a priority column (will probably not be used until D6).