You are here

function nodeaccess_install in Nodeaccess 5

Same name and namespace in other branches
  1. 8.2 nodeaccess.install \nodeaccess_install()
  2. 8 nodeaccess.install \nodeaccess_install()
  3. 6.2 nodeaccess.install \nodeaccess_install()
  4. 6 nodeaccess.install \nodeaccess_install()
  5. 7 nodeaccess.install \nodeaccess_install()

Implementation of hook_install().

File

./nodeaccess.install, line 6

Code

function nodeaccess_install() {

  // Create tables.
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {nodeaccess} (\n        nid int(10) unsigned NOT NULL default '0',\n        gid int(10) unsigned NOT NULL default '0',\n        realm varchar(255) NOT NULL default '',\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        PRIMARY KEY (nid,gid,realm)\n      )");

      /*!40100 DEFAULT CHARACTER SET utf8 */
      db_query("CREATE TABLE {nodeaccess_role_alias} (\n        rid int(10) unsigned NOT NULL default '0',\n        name varchar(50) NOT NULL default '',\n        weight int(3) NOT NULL default '0',\n        PRIMARY KEY (rid)\n      )");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {nodeaccess} (\n        nid int_unsigned NOT NULL default '0',\n        gid int_unsigned NOT NULL default '0',\n        realm varchar(255) NOT NULL default '',\n        grant_view smallint_unsigned NOT NULL default '0',\n        grant_update smallint_unsigned NOT NULL default '0',\n        grant_delete smallint_unsigned NOT NULL default '0',\n        PRIMARY KEY (nid,gid,realm)\n      )");
      db_query("CREATE TABLE {nodeaccess_role_alias} (\n        rid int_unsigned NOT NULL default '0',\n        name varchar(50) NOT NULL default '',\n        weight smallint NOT NULL default '0',\n        PRIMARY KEY (rid)\n      )");
      break;
  }

  // Set up default permissions to be view for authenticated and
  // anonymous users, and all permissions for author.
  $grants = array();
  $grants[] = array(
    'gid' => 1,
    'realm' => 'nodeaccess_rid',
    'grant_view' => 1,
    'grant_update' => 0,
    'grant_delete' => 0,
  );
  $grants[] = array(
    'gid' => 2,
    'realm' => 'nodeaccess_rid',
    'grant_view' => 1,
    'grant_update' => 0,
    'grant_delete' => 0,
  );
  $author_prefs = array();
  foreach (node_get_types() as $type => $name) {
    variable_set('nodeaccess_' . $type, $grants);
    $author_prefs[$type] = array(
      'grant_view' => 1,
      'grant_update' => 1,
      'grant_delete' => 1,
    );
  }
  variable_set('nodeaccess_authors', $author_prefs);

  // Set up all permissions to be editable by default.
  $grant_prefs = array(
    'view' => 1,
    'edit' => 1,
    'delete' => 1,
  );
  variable_set('nodeaccess-grants', $grant_prefs);
}