You are here

book_access.install in Book access 5

Same filename and directory in other branches
  1. 6.2 book_access.install
  2. 6 book_access.install
  3. 7.2 book_access.install

File

book_access.install
View source
<?php

/**
 * Implements hook_enable().
 */
function book_access_enable() {
  node_access_rebuild();
}

/**
 * Implements hook_disable().
 */
function book_access_disable() {
  book_access_enabled(FALSE);
  node_access_rebuild();
}

/**
 * Implements hook_install().
 */
function book_access_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("\n        CREATE TABLE IF NOT EXISTS {book_access} (\n          nid 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          KEY nid (nid),\n          KEY rid (rid)\n        );\n      ");
      break;
    case 'pgsql':
      db_query("\n        CREATE TABLE {book_access} (\n          nid 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          PRIMARY KEY (nid, rid)\n        );\n      ");
      break;
  }
  db_query("UPDATE {system} SET weight = 2 WHERE name = 'book_access'");
}

/**
 * Implements hook_update_N().
 */
function book_access_update_1() {
  $ret = array();
  $ret[] = update_sql("UPDATE {system} SET weight = 2 WHERE name = 'book_access'");
  return $ret;
}

/**
 * Implements hook_uninstall().
 */
function book_access_uninstall() {
  db_query('DROP TABLE {book_access}');
}