You are here

cas_roles.install in CAS roles 7

Same filename and directory in other branches
  1. 8 cas_roles.install
  2. 6 cas_roles.install
  3. 7.2 cas_roles.install

Installation hooks for the CAS Attributes module.

File

cas_roles.install
View source
<?php

/**
 * @file
 * Installation hooks for the CAS Attributes module.
 */

/**
 * Implements hook_uninstall().
 */
function cas_roles_uninstall() {

  // Delete variables.
  variable_del('cas_roles_sync_every_login');
  variable_del('cas_roles_behavior');
  variable_del('cas_roles_roles');
  variable_del('cas_roles_relations');
  variable_del('cas_roles_require_a_role_create');
  variable_del('cas_roles_require_a_role_login');
}

/**
 * Implements hook_requirements().
 */
function cas_roles_requirements($phase) {
  $requirements = array();
  $t = get_t();
  if ($phase == 'runtime') {
    if (!function_exists('cas_phpcas_attributes')) {
      $requirements['cas_roles'] = array(
        'title' => $t('CAS'),
        'value' => $t('Outdated'),
        'severity' => REQUIREMENT_WARNING,
        'description' => $t('CAS roles requires <a href="@url">CAS</a> version 7.x-1.0 or later.', array(
          '@url' => 'http://drupal.org/project/cas',
        )),
      );
    }

    // Okay to call functions from cas.module since we are in the runtime
    // phase. We hide errors here in case phpcas could not be loaded.
    if ($version = @cas_phpcas_load()) {
      if (!method_exists('phpCAS', 'getAttributes')) {
        $requirements['cas_roles_phpcas'] = array(
          'title' => $t('phpCAS (Attribute support)'),
          'value' => $version,
          'severity' => REQUIREMENT_WARNING,
          'description' => $t('CAS roles requires <a href="@url">phpCAS</a> version 1.1.0 or later.', array(
            '@url' => 'https://wiki.jasig.org/display/CASC/phpCAS',
          )),
        );
      }
    }
  }
  return $requirements;
}

/**
 * Update cas_role mapping.
 */
function cas_roles_update_7001() {
  $relations = variable_get('cas_roles_relations', array());
  $new_relations = array();
  foreach (user_roles(TRUE) as $rid => $role) {
    if (isset($relations[$rid])) {
      $new_relations[$role] = $relations[$rid];
    }
  }
  variable_set('cas_roles_relations', $new_relations);
}

Functions

Namesort descending Description
cas_roles_requirements Implements hook_requirements().
cas_roles_uninstall Implements hook_uninstall().
cas_roles_update_7001 Update cas_role mapping.