You are here

role_export.install in Role Export 6

Same filename and directory in other branches
  1. 7 role_export.install

Install, Uninstall, Schema and Update functions for role_export

File

role_export.install
View source
<?php

/**
 * @file
 * Install, Uninstall, Schema and Update functions for role_export
 */

/**
 * Implements hook_schema_alter().
 */
function role_export_schema_alter(&$schema) {

  // Add machine_name field to the 'role' schema.
  $schema['role']['fields']['machine_name'] = array(
    'description' => 'The machine name assigned by the user during creation of the role.',
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
  );
}

/**
 * Implements hook_install().
 */
function role_export_install() {
  $ret = array();

  // Add machine_name field to the 'role' table.
  db_add_field($ret, 'role', 'machine_name', array(
    'description' => 'The machine name assigned by the user during creation of the role.',
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
  ));

  // Update any existing roles (except anonymous, authenticated) to have a
  // machine name and save it to the 'role' table.
  $roles = db_query("SELECT rid, name FROM {role} WHERE rid > 2");
  while ($role = db_fetch_object($roles)) {
    $rid = $role->rid;
    $machine_name = str_replace(' ', '_', strtolower($role->name));
    db_query("UPDATE {role} SET machine_name = '%s' WHERE rid = %d", $machine_name, $rid);
  }
}

/**
 * Implements hook_uninstall().
 */
function role_export_uninstall() {
  $ret = array();
  db_drop_field($ret, 'role', 'machine_name');
}