You are here

shib_auth.install in Shibboleth Authentication 7.4

Install file of the Shibboleth authentication module for Drupal system.

File

shib_auth.install
View source
<?php

/**
 * @file
 * Install file of the Shibboleth authentication module for Drupal system.
 */

/**
 * Implements hook_uninstall().
 *
 * Hook to uninstall variables and the block, witch were created and used by the
 * module.
 */
function shib_auth_uninstall() {

  // Drop variables.
  $variables = array(
    'shib_auth_link_text',
    'shib_auth_handler_url',
    'shib_auth_handler_protocol',
    'shib_auth_wayf_uri',
    'shib_auth_full_handler_url',
    'shib_auth_full_logout_url',
    'shib_auth_username_variable',
    'shib_auth_email_variable',
    'shib_auth_auto_destroy_session',
    'shib_auth_logout_url',
    'shib_auth_login_url',
    'shib_auth_debug_state',
    'shib_auth_debug_url',
    'shib_auth_enable_custom_mail',
    'shib_auth_define_username',
    'shib_auth_account_linking',
    'shib_auth_is_passive',
    'shib_auth_forceauthn',
    'shib_auth_terms_accept',
    'shib_auth_terms_url',
    'shib_auth_terms_ver',
    'shib_auth_force_https',
    'shib_auth_version',
  );
  foreach ($variables as $variable) {
    variable_del($variable);
  }
  drupal_set_message(t('The Shibboleth authentication module was uninstalled successfully.'));
}

/**
 * Implements hook_schema().
 *
 * This is how the schema of the module will look like.
 */
function shib_auth_schema() {
  $schema = array();
  $schema['shib_authmap'] = array(
    'description' => 'Stores shibboleth authentication mapping from persistent IDs to drupal users.',
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'The id of the authentication mapping rule',
      ),
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The {users}.uid, which the persistent ID will be mapped to',
      ),
      'targeted_id' => array(
        'type' => 'varchar',
        'length' => 255,
        'default' => '',
        'not null' => TRUE,
        'description' => 'The persistent ID, which will be mapped to a drupal uid',
      ),
      'idp' => array(
        'type' => 'varchar',
        'length' => 255,
        'default' => '',
        'description' => 'The IdP, the user got her credentials',
      ),
      'consentver' => array(
        'type' => 'varchar',
        'length' => 16,
        'default' => '',
        'description' => 'The version of terms and conditions, which was accepted by the user',
      ),
      'created' => array(
        'type' => 'int',
        'default' => 0,
        'not null' => TRUE,
        'description' => 'Timestamp the mapping was created',
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'unique keys' => array(
      'targeted_id' => array(
        'targeted_id',
      ),
    ),
  );
  $schema['shib_auth'] = array(
    'description' => 'Stores shibboleth authentication rules',
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'The id of the Shibboleth role assignment rule',
      ),
      'field' => array(
        'type' => 'varchar',
        'length' => 128,
        'default' => '',
        'description' => 'The observed server variable.',
      ),
      'regexpression' => array(
        'type' => 'varchar',
        'length' => 128,
        'default' => '',
        'description' => 'The joint regular expression.',
      ),
      'role' => array(
        'type' => 'varchar',
        'length' => 128,
        'default' => '',
        'description' => 'The assigned role.',
      ),
      'sticky' => array(
        'type' => 'int',
        'default' => 0,
        'description' => 'Sticky status',
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  return $schema;
}

/**
 * Updates the database structure for compatibility with Drupal 7.
 *
 * D7 database API don't support datetime type anymore, so we change the
 * database structure.
 */
function shib_auth_update_7000(&$sandbox) {

  // Save the created datetime temporaly.
  $res = db_select('shib_authmap', 'sa')
    ->fields('sa', array(
    'id',
    'created',
  ))
    ->execute()
    ->fetchAll();

  // Change to the created column type from datetime to int.
  db_add_field('shib_authmap', 'created_unix', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => FALSE,
  ));

  // Fill the database with unixtimestamps.
  foreach ($res as $row) {
    if (is_numeric($row->created)) {

      // Suppose it's already a timestamp, see #1380826.
      continue;
    }
    if (!($created_unix = strtotime($row->created))) {
      $created_unix = $row->created;
    }
    db_update('shib_authmap')
      ->fields(array(
      'created_unix' => $created_unix,
    ))
      ->condition('id', $row->id, '=')
      ->execute();
  }
  db_drop_field('shib_authmap', 'created');
  db_change_field('shib_authmap', 'created_unix', 'created', array(
    'type' => 'int',
  ));

  // Update the menu system cache.
  menu_rebuild();
}

/**
 * Alter uid field so it supports larger values.
 */
function shib_auth_update_7001() {
  db_change_field('shib_authmap', 'uid', 'uid', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
    'description' => 'The {users}.uid, which the persistent ID will be mapped to',
  ));
}

Functions

Namesort descending Description
shib_auth_schema Implements hook_schema().
shib_auth_uninstall Implements hook_uninstall().
shib_auth_update_7000 Updates the database structure for compatibility with Drupal 7.
shib_auth_update_7001 Alter uid field so it supports larger values.