You are here

acl.install in ACL 6

Same filename and directory in other branches
  1. 8 acl.install
  2. 5 acl.install
  3. 7 acl.install

Install, update and uninstall functions for the acl module.

File

acl.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the acl module.
 */

/**
 * Implementation of hook_install().
 */
function acl_install() {
  drupal_install_schema('acl');
}

/**
 * Implementation of hook_schema().
 */
function acl_schema() {
  $schema['acl'] = array(
    'description' => 'The base Access Control Lists table.',
    'fields' => array(
      'acl_id' => array(
        'description' => 'Primary key: unique ACL ID.',
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'module' => array(
        'description' => 'The name of the module that created this ACL entry.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => 'A name (or other identifying information) for this ACL entry, given by the module that created it.',
        'type' => 'varchar',
        'length' => 255,
      ),
      'number' => array(
        'description' => "A number for this ACL entry, given by the module that created it; use either 'name' or 'number'.",
        'type' => 'int',
      ),
    ),
    'primary key' => array(
      'acl_id',
    ),
    'indexes' => array(
      'module_name_number' => array(
        array(
          'module',
          64,
        ),
        array(
          'name',
          64,
        ),
        'number',
      ),
      'module_number' => array(
        array(
          'module',
          64,
        ),
        'number',
      ),
    ),
  );
  $schema['acl_user'] = array(
    'description' => 'Identifies {users} to which the referenced {acl} entry applies.',
    'fields' => array(
      'acl_id' => array(
        'description' => 'The {acl}.acl_id of the entry.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'uid' => array(
        'description' => 'The {user}.uid to which this {acl} entry applies.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'acl_id',
      'uid',
    ),
    'indexes' => array(
      'uid' => array(
        'uid',
      ),
    ),
  );
  $schema['acl_node'] = array(
    'description' => 'Identifies {node}s to which the referenced {acl} entry applies and defines the permissions granted.',
    'fields' => array(
      'acl_id' => array(
        'description' => 'The {acl}.acl_id of the entry.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'nid' => array(
        'description' => 'The {node}.nid to grant permissions for.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'grant_view' => array(
        'description' => 'Whether to grant "view" permission.',
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'grant_update' => array(
        'description' => 'Whether to grant "update" permission.',
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'grant_delete' => array(
        'description' => 'Whether to grant "delete" permission.',
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'priority' => array(
        'description' => 'The priority of this grant record (for hook_node_access_records()).',
        'type' => 'int',
        'size' => 'small',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'acl_id',
      'nid',
    ),
    'indexes' => array(
      'nid' => array(
        'nid',
      ),
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_requirements().
 */
function acl_requirements($phase) {
  $requirements = array();
  $t = get_t();

  // Check for existence of incompatible Authcache contrib module.
  if ($phase == 'runtime' && module_exists('authcache')) {
    $requirements['acl'] = array(
      'title' => $t('!ACL compatibility', array(
        '!ACL' => '<a href="http://drupal.org/project/acl">ACL</a>',
      )),
      'value' => $t('!Authcache changes the behavior of Drupal in a way that is fundamentally incompatible with the per-user access control implemented by ACL. Please disable it!', array(
        '!Authcache' => '<a href="http://drupal.org/project/authcache">Authcache</a>',
      )),
      'severity' => REQUIREMENT_ERROR,
    );
  }
  return $requirements;
}

/*
 * Implementation of hook_uninstall().
 */
function acl_uninstall() {
  drupal_uninstall_schema('acl');
}

/**
 * Fixes primary keys
 */
function acl_update_2() {
  $ret = array();

  // drop the previously created indexes (except for acl_user.uid)
  db_drop_index($ret, 'acl', 'acl_id');
  db_drop_index($ret, 'acl_user', 'acl_id');
  db_drop_index($ret, 'acl_node', 'acl_id');
  db_drop_index($ret, 'acl_node', 'nid');

  // create new indexes (as primary keys this time)
  db_add_primary_key($ret, 'acl', array(
    'acl_id',
  ));
  db_add_primary_key($ret, 'acl_user', array(
    'acl_id',
    'uid',
  ));
  db_add_primary_key($ret, 'acl_node', array(
    'acl_id',
    'nid',
  ));
  return $ret;
}

/**
 * Put back acl_node(nid) index for deleting nodes and clean up {acl_node}.
 */
function acl_update_4() {
  $ret = array();
  db_add_index($ret, 'acl_node', 'nid', array(
    'nid',
  ));
  $ret[] = update_sql("DELETE FROM {acl_node} WHERE nid NOT IN (SELECT nid FROM {node})");
  return $ret;
}

/**
 * Clean up {acl_user}.
 */
function acl_update_5() {
  $ret = array();
  $ret[] = update_sql("DELETE FROM {acl_user} WHERE uid NOT IN (SELECT uid FROM {users})");
  return $ret;
}

/**
 * Add 'priority' column.
 */
function acl_update_6() {
  $ret = array();
  db_add_field($ret, 'acl_node', 'priority', array(
    'type' => 'int',
    'size' => 'small',
    'not null' => TRUE,
    'default' => 0,
  ));
  return $ret;
}

/**
 * Change acl_id to auto-increment.
 */
function acl_update_6000() {
  $ret = array();
  db_change_field($ret, 'acl', 'acl_id', 'acl_id', array(
    'type' => 'serial',
    'not null' => TRUE,
  ));

  // (Dropping and recreating the primary key on an auto_increment column would cause a MySQL failure.)
  db_change_field($ret, 'acl', 'module', 'module', array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
  ));
  db_change_field($ret, 'acl', 'name', 'name', array(
    'type' => 'varchar',
    'length' => 255,
  ));
  db_add_index($ret, 'acl_node', 'nid', array(
    'nid',
  ));
  return $ret;
}

/**
 * Add index that should have been added when upgrading from D5.
 */
function acl_update_6001() {
  $ret = array();
  @db_add_index($ret, 'acl_node', 'nid', array(
    'nid',
  ));
  return $ret['success'] ? $ret : array();

  // ignore possible error, if the index already exists
}

/**
 * Add 'number' column, add indexes.
 */
function acl_update_6002() {
  $ret = array();
  db_add_field($ret, 'acl', 'number', array(
    'type' => 'int',
    'description' => "A number for this ACL entry, given by the module that created it; use either 'name' or 'number'.",
  ));
  db_add_index($ret, 'acl', 'name', array(
    'name',
  ));
  db_add_index($ret, 'acl', 'number', array(
    'number',
  ));
  return $ret;
}

/**
 * Install better indexes.
 */
function acl_update_6003() {
  $ret = array();
  db_drop_index($ret, 'acl', 'name');
  db_drop_index($ret, 'acl', 'number');
  db_add_index($ret, 'acl', 'module_name_number', array(
    array(
      'module',
      64,
    ),
    array(
      'name',
      64,
    ),
    'number',
  ));
  db_add_index($ret, 'acl', 'module_number', array(
    array(
      'module',
      64,
    ),
    'number',
  ));
  return $ret;
}

Functions

Namesort descending Description
acl_install Implementation of hook_install().
acl_requirements Implementation of hook_requirements().
acl_schema Implementation of hook_schema().
acl_uninstall
acl_update_2 Fixes primary keys
acl_update_4 Put back acl_node(nid) index for deleting nodes and clean up {acl_node}.
acl_update_5 Clean up {acl_user}.
acl_update_6 Add 'priority' column.
acl_update_6000 Change acl_id to auto-increment.
acl_update_6001 Add index that should have been added when upgrading from D5.
acl_update_6002 Add 'number' column, add indexes.
acl_update_6003 Install better indexes.