You are here

user_restrictions.install in User restrictions 7

Implementing schema for the User restrictions module.

File

user_restrictions.install
View source
<?php

/**
 * @file
 * Implementing schema for the User restrictions module.
 */

/**
 * Implements hook_schema().
 */
function user_restrictions_schema() {
  $schema['user_restrictions'] = array(
    'description' => 'Stores user restrictions.',
    'fields' => array(
      'urid' => array(
        'description' => 'Primary Key: Unique user restriction ID.',
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'mask' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Text mask used for filtering restrictions.',
      ),
      'type' => array(
        'description' => 'Type of access rule: name, mail, or any value defined from a third-party module.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'subtype' => array(
        'description' => 'Sub-type of access rule.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'status' => array(
        'description' => 'Whether the restriction is to allow (1), or deny access (0).',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
      'expire' => array(
        'description' => 'A Unix timestamp indicating when the restriction expires.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'subtype' => array(
        array(
          'subtype',
          32,
        ),
      ),
      'type' => array(
        array(
          'type',
          32,
        ),
      ),
      'status' => array(
        'status',
      ),
      'expire' => array(
        'expire',
      ),
    ),
    'primary key' => array(
      'urid',
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 */
function user_restrictions_install() {
  db_query("UPDATE {system} SET weight = 10 WHERE name = 'user_restrictions' AND type = 'module'");
  drupal_set_message(st('With the user_restrictions_ui module enabled, you may <a href="@import">import access rules</a>.', array(
    '@import' => 'admin/config/people/user-restrictions/import',
  )));
}

/**
 * Adds the sub-type field to the database table.
 */
function user_restrictions_update_7100(&$sandbox) {
  if (!db_field_exists('user_restrictions', 'subtype')) {
    db_add_field('user_restrictions', 'subtype', array(
      'type' => 'varchar',
      'length' => 255,
      'not null' => TRUE,
      'default' => '',
    ), array(
      'indexes' => array(
        'subtype' => array(
          array(
            'subtype',
            32,
          ),
        ),
      ),
    ));
  }
}

/**
 * Updates the Drupal registry.
 */
function user_restrictions_update_7101(&$sandbox) {
  registry_update();
  db_update('system')
    ->fields(array(
    'weight' => 10,
  ))
    ->condition('name', 'user_restrictions')
    ->execute();
}

/**
 * Imports username and e-mail masks from the {access} table.
 */
function user_restrictions_update_7102(&$sandbox) {

  // Use the batch operation defined in user_restrictions_ui
  $batch = array(
    'title' => t('Importing'),
    'operations' => array(
      array(
        'user_restrictions_ui_import',
        array(),
      ),
    ),
    'file' => drupal_get_path('module', 'user_restrictions_ui') . '/user_restrictions_ui.admin.inc',
    'finished' => 'user_restrictions_ui_import_finished',
  );
  batch_set($batch);
}

Functions

Namesort descending Description
user_restrictions_install Implements hook_install().
user_restrictions_schema Implements hook_schema().
user_restrictions_update_7100 Adds the sub-type field to the database table.
user_restrictions_update_7101 Updates the Drupal registry.
user_restrictions_update_7102 Imports username and e-mail masks from the {access} table.