You are here

function nodeaccess_update_3 in Nodeaccess 6

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

File

./nodeaccess.install, line 109

Code

function nodeaccess_update_3() {

  // Create new nodeaccess_role_alias table.
  $schema['nodeaccess_role_alias'] = array(
    'fields' => array(
      'rid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 50,
        'not null' => TRUE,
        'default' => '',
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'rid',
    ),
  );
  $ret = array();
  db_create_table($ret, 'nodeaccess_role_alias', $schema['nodeaccess_role_alias']);

  // 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);
  return $ret;
}