You are here

nodeaccess.install in Nodeaccess 7

Install/uninstall functions for Nodeaccess.

File

nodeaccess.install
View source
<?php

/**
 * @file
 * Install/uninstall functions for Nodeaccess.
 */

/**
 * Implements hook_enable().
 */
function nodeaccess_enable() {
}

/**
 * Implements hook_disable().
 */
function nodeaccess_disable() {
  nodeaccess_disabling(TRUE);
}

/**
 * Implements hook_install().
 */
function nodeaccess_install() {

  // Set up default permissions to be view for authenticated and
  // anonymous users, and all permissions for author.
  $grants = array();
  $role_perms = user_role_permissions(array(
    1 => 1,
    2 => 2,
  ));
  $role_perms[1]['access content'] = isset($role_perms[1]['access content']) ? intval($role_perms[1]['access content']) : 0;
  $role_perms[2]['access content'] = isset($role_perms[2]['access content']) ? intval($role_perms[2]['access content']) : 0;

  // Anonymous user setting.
  $grants[] = array(
    'gid' => 1,
    'realm' => 'nodeaccess_rid',
    'grant_view' => $role_perms[1]['access content'],
  );

  // Authenticated user setting.
  $grants[] = array(
    'gid' => 2,
    'realm' => 'nodeaccess_rid',
    'grant_view' => $role_perms[2]['access content'],
  );
  $author_prefs = array();
  foreach (node_type_get_types() as $type => $name) {

    // We check the edit permissions for anonymous and authenticated users.
    $edit_perm = 'edit any ' . $type . ' content';
    $role_perms[1][$edit_perm] = isset($role_perms[1][$edit_perm]) ? intval($role_perms[1][$edit_perm]) : 0;
    $role_perms[2][$edit_perm] = isset($role_perms[2][$edit_perm]) ? intval($role_perms[2][$edit_perm]) : 0;
    $grants[0]['grant_update'] = $role_perms[1][$edit_perm];
    $grants[1]['grant_update'] = $role_perms[2][$edit_perm];

    // We check the delete permissions for anonymous and authenticated users.
    $delete_perm = 'delete any ' . $type . ' content';
    $role_perms[1][$delete_perm] = isset($role_perms[1][$delete_perm]) ? intval($role_perms[1][$delete_perm]) : 0;
    $role_perms[2][$delete_perm] = isset($role_perms[2][$delete_perm]) ? intval($role_perms[2][$delete_perm]) : 0;
    $grants[0]['grant_delete'] = $role_perms[1][$delete_perm];
    $grants[1]['grant_delete'] = $role_perms[2][$delete_perm];
    variable_set('nodeaccess_' . $type, $grants);
    $author_prefs[$type] = array(
      'grant_view' => 0,
      'grant_update' => 0,
      'grant_delete' => 0,
    );
  }
  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);
}

/**
 * Implements hook_schema().
 */
function nodeaccess_schema() {
  $schema['nodeaccess'] = array(
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'gid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'realm' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'grant_view' => array(
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'grant_update' => array(
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'grant_delete' => array(
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'nid',
      'gid',
      'realm',
    ),
  );
  $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',
    ),
  );
  return $schema;
}

/**
 * Implements hook_uninstall().
 */
function nodeaccess_uninstall() {

  // Remove variables.
  variable_del('nodeaccess-priority');
  variable_del('nodeaccess-preserve');
  variable_del('nodeaccess-grants');
  variable_del('nodeaccess-roles');
  variable_del('nodeaccess-types');
  variable_del('nodeaccess_authors');
  foreach (node_type_get_types() as $type => $name) {
    variable_del('nodeaccess_' . $type);
    variable_del('nodeaccess_' . $type . '_userreference');
  }

  // Remove tables.
  drupal_uninstall_schema('nodeaccess');
}

/**
 * Flag nodeaccess permissions as needing a rebuild. Rebuild permissions from the status page.
 */
function nodeaccess_update_7105() {
  node_access_needs_rebuild();
}

Functions

Namesort descending Description
nodeaccess_disable Implements hook_disable().
nodeaccess_enable Implements hook_enable().
nodeaccess_install Implements hook_install().
nodeaccess_schema Implements hook_schema().
nodeaccess_uninstall Implements hook_uninstall().
nodeaccess_update_7105 Flag nodeaccess permissions as needing a rebuild. Rebuild permissions from the status page.