Projet

Général

Profil

Paste
Télécharger (2,86 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / cas_attributes / cas_attributes.install @ 87dbc3bf

1
<?php
2

    
3
/**
4
 * @file
5
 * Installation hooks for the CAS Attributes module.
6
 */
7

    
8
/**
9
 * Implements hook_uninstall().
10
 */
11
function cas_attributes_uninstall() {
12
  // Delete variables.
13
  variable_del('cas_attributes');
14
}
15

    
16
/**
17
 * Implements hook_requirements().
18
 */
19
function cas_attributes_requirements($phase) {
20
  $requirements = array();
21
  $t = get_t();
22

    
23
  if ($phase == 'runtime') {
24
    if (!function_exists('cas_phpcas_attributes')) {
25
      $requirements['cas_attributes'] = array(
26
        'title' => $t('CAS'),
27
        'value' => $t('Outdated'),
28
        'severity' => REQUIREMENT_WARNING,
29
        'description' => $t('CAS attributes requires <a href="@url">CAS</a> version 7.x-1.0 or later.', array('@url' => 'http://drupal.org/project/cas')),
30
      );
31
    }
32

    
33
    // Okay to call functions from cas.module since we are in the runtime
34
    // phase. We hide errors here in case phpcas could not be loaded.
35
    if ($version = @cas_phpcas_load()) {
36
      if (!method_exists('phpCAS', 'getAttributes')) {
37
        $requirements['cas_attributes_phpcas'] = array(
38
          'title' => $t('phpCAS (Attribute support)'),
39
          'value' => $version,
40
          'severity' => REQUIREMENT_WARNING,
41
          'description' => $t('CAS attributes requires <a href="@url">phpCAS</a> version 1.1.0 or later.', array('@url' => 'https://wiki.jasig.org/display/CASC/phpCAS')),
42
        );
43
      }
44
    }
45
  }
46
  return $requirements;
47
}
48

    
49
function cas_attributes_update_7100() {
50
  $attr = variable_get('cas_attributes', array());
51
  if (array_key_exists('relations', $attr)) {
52
    foreach ($attr['relations'] as $key => $value) {
53
      $attr['relations'][$key] = preg_replace('/\[cas:attribute:([^:\?\]]*)]/', '[cas:attribute:$1:first]', $value);
54
    }
55
  }
56
  variable_set('cas_attributes', $attr);
57
}
58

    
59
function cas_attributes_update_7101() {
60
  // split the various settings up into their own smaller, more manageable variables
61
  $attr = variable_get('cas_attributes', array());
62
  if(array_key_exists('overwrite', $attr)) {
63
    variable_set('cas_attributes_overwrite', $attr['overwrite']);
64
  }
65
  if(array_key_exists('sync_every_login', $attr)) {
66
    variable_set('cas_attributes_sync_every_login', $attr['sync_every_login']);
67
  }
68
  if(array_key_exists('relations', $attr)) {
69
    variable_set('cas_attributes_relations', $attr['relations']);
70
  }
71
  if(array_key_exists('roles', $attr)) {
72
    if(array_key_exists('manage', $attr['roles'])) {
73
      variable_set('cas_attributes_roles_manage', $attr['roles']['manage']);
74
    }
75
    if(array_key_exists('mapping', $attr['roles'])) {
76
      variable_set('cas_attributes_roles_mapping', $attr['roles']['mapping']);
77
    }
78
  }
79

    
80
  // (this one should only exist if cas_ldap has been used at some point)
81
  if(array_key_exists('ldap', $attr)) {
82
    if(array_key_exists('server', $attr['ldap'])) {
83
      variable_set('cas_attributes_ldap_server', $attr['ldap']['server']);
84
    }
85
  }
86

    
87
  variable_del('cas_attributes');
88
}