You are here

function nodeaccess_update_3 in Nodeaccess 5

Same name and namespace in other branches
  1. 6.2 nodeaccess.install \nodeaccess_update_3()
  2. 6 nodeaccess.install \nodeaccess_update_3()

File

./nodeaccess.install, line 128

Code

function nodeaccess_update_3() {

  // Create new nodeaccess_role_alias table.
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      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_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 alias names to match role names and default
  // weights to 0. Do this for allowed roles only.
  $allowedrole = variable_get('nodeaccess-roles', array());
  foreach ($allowedrole as $rid => $value) {
    if ($value) {
      db_query("INSERT INTO {nodeaccess_role_alias} SELECT rid, name, 0 FROM {role} WHERE rid = %d", $rid);
    }
  }

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