You are here

config_perms.install in Custom Permissions 6.2

Same filename and directory in other branches
  1. 8.2 config_perms.install
  2. 7.2 config_perms.install

Installation file

File

config_perms.install
View source
<?php

/**
 * @file
 * Installation file
 */

/**
 * Implementation of hook_install().
 */
function config_perms_install() {

  // Create tables.
  drupal_install_schema('config_perms');
  _config_perms_install_data();
  cache_clear_all('config_perms', 'cache');
  menu_rebuild();
}

/**
 * Implementation of hook_uninstall().
 */
function config_perms_uninstall() {

  // Remove tables.
  drupal_uninstall_schema('config_perms');
  cache_clear_all('config_perms', 'cache');
  menu_rebuild();
}

/**
 * Implementation of hook_schema().
 */
function config_perms_schema() {
  $schema['config_perms'] = array(
    'description' => 'The config perms table.',
    // Optional CTools export.inc integration
    'export' => array(
      'key' => 'machine_name',
      'identifier' => 'config_perms',
      'default hook' => 'config_perms',
      'api' => array(
        'owner' => 'config_perms',
        'api' => 'config_perms',
        'minimum_version' => 1,
        'current_version' => 1,
      ),
    ),
    'fields' => array(
      'machine_name' => array(
        'description' => 'The primary identifier for a permission',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'pid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Primary ID field for the table. Not used for anything except internal lookups.',
        'no export' => TRUE,
      ),
      'status' => array(
        'description' => 'Whether this field is enabled or not.',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 1,
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'path' => array(
        'type' => 'text',
        'size' => 'medium',
        'not null' => TRUE,
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array(
      'pid',
    ),
    'unique keys' => array(
      'name' => array(
        'machine_name',
      ),
    ),
  );
  return $schema;
}
function _config_perms_install_data() {
  $perms = array(
    'administer administration theme' => array(
      'admin/settings/admin',
    ),
    'administer clean-urls' => array(
      'admin/settings/clean-urls',
    ),
    'administer date-time' => array(
      'admin/settings/date-time',
      'admin/settings/date-time/lookup',
    ),
    'administer error reporting' => array(
      'admin/settings/error-reporting',
    ),
    'administer file system' => array(
      'admin/settings/file-system',
    ),
    'administer performance' => array(
      'admin/settings/performance',
    ),
    'administer site information' => array(
      'admin/settings/site-information',
    ),
    'administer site maintenance' => array(
      'admin/settings/site-maintenance',
    ),
    'administer modules' => array(
      'admin/build/modules',
      'admin/build/modules/list/confirm',
      'admin/build/modules/uninstall',
      'admin/build/modules/uninstall/confirm',
    ),
    'administer user profile fields' => array(
      'admin/user/profile',
    ),
    'administer content node settings' => array(
      'admin/content/node-settings',
    ),
    'display site building menu' => array(
      'admin/build',
    ),
    'display site configuration menu' => array(
      'admin/settings',
    ),
  );
  foreach ($perms as $name => $paths) {
    db_query("INSERT INTO {config_perms} (machine_name, status, name, path) VALUES ('%s', %d, '%s', %b)", strtolower(preg_replace('/[^a-zA-Z0-9_]+/', '_', $name)), 1, $name, serialize($paths));
  }
}
function config_perms_update_6200() {
  $ret = array();
  $schema = config_perms_schema();
  db_create_table($ret, 'config_perms', $schema['config_perms']);
  _config_perms_install_data();
  cache_clear_all('config_perms', 'cache');
  return $ret;
}