Projet

Général

Profil

Révision 32700c57

Ajouté par Assos Assos il y a environ 5 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/ldap/ldap_user/ldap_user.cron.inc
2 2

  
3 3
/**
4 4
 * @file
5
 * cron relate functions
6
 *
5
 * Cron relate functions.
7 6
 */
8 7

  
9 8
/**
10
 * function to respond to ldap associated drupal accounts which no
11
 * longer have a related LDAP entry
9
 * Function to respond to ldap associated drupal accounts which no
10
 * longer have a related LDAP entry.
12 11
 *
13 12
 * @param LdapUserConf $ldap_user_conf
14 13
 *
15 14
 * @return boolean FALSE on error or incompletion or TRUE otherwise
16 15
 */
17 16
function _ldap_user_orphans($ldap_user_conf) {
18

  
19
  // return TRUE; // this is untested code
20

  
21 17
  if (!$ldap_user_conf->orphanedDrupalAcctBehavior ||
22 18
    $ldap_user_conf->orphanedDrupalAcctBehavior == 'ldap_user_orphan_do_not_check') {
23 19
    return TRUE;
......
40 36
    ->fieldCondition('ldap_user_puid', 'value', 'NULL', '!=')
41 37
    ->fieldCondition('ldap_user_current_dn', 'value', 'NULL', '!=')
42 38
    ->propertyCondition('uid', $last_uid_checked, '>')
39
    ->propertyCondition('status', 1)
43 40
    ->propertyOrderBy('uid', 'ASC')
44 41
    ->range(0, $ldap_user_conf->orphanedCheckQty)
45
    ->addMetaData('account', user_load(1)); // run the query as user 1
42
  // Run the query as user 1.
43
    ->addMetaData('account', user_load(1));
46 44
  $result = $query->execute();
47 45

  
48
  $email_list = array();
46
  $email_list = [];
49 47
  $ldap_servers = ldap_servers_get_servers(NULL, 'enabled');
50
  $watchdogs_sids_missing_watchdogged = array();
48
  $watchdogs_sids_missing_watchdogged = [];
51 49
  /**
52
   * first produce array of form:
53
   *  $drupal_users[$sid][$puid_attr][$puid]['exists'] = FALSE | TRUE;
54
   *  signifying if corresponding LDAP Entry exists
50
   * First produce array of form:
51
   *  $drupal_users[$sid][$puid_attr][$puid]['exists'] = bool
52
   *  signifying if corresponding LDAP Entry exists.
55 53
   */
56 54
  if (!(isset($result['user']) && count($result['user']) > 0)) {
57 55
    return TRUE;
......
60 58
  $uids = array_keys($result['user']);
61 59
  $user_count = count($uids);
62 60

  
63
  // if maxed out reset uid check counter
61
  // If maxed out reset uid check counter.
64 62
  if ($user_count < $ldap_user_conf->orphanedCheckQty) {
65 63
    variable_set('ldap_user_cron_last_uid_checked', 1);
66 64
  }
......
69 67
  }
70 68

  
71 69
  $batches = floor($user_count / LDAP_SERVERS_MAXFILTER_ORS) + 1;
72
  // e.g. 175 users and  50 max ldap query ors will yield 4 batches
70
  // e.g. 175 users and  50 max ldap query ors will yield 4 batches.
73 71
  for ($batch = 1; $batch <= $batches; $batch++) {
74 72
    $email_list = _ldap_user_orphan_process_batch($ldap_user_conf, $batch, $user_count, $uids, $ldap_servers, $watchdogs_sids_missing_watchdogged, $query, $email_list);
75 73
  }
76 74

  
77 75
  if (count($email_list) > 0) {
78 76
    $site_email = variable_get('site_mail', FALSE);
79
    $params = array('accounts' => $email_list);
77
    $params = ['accounts' => $email_list];
80 78
    if ($site_email) {
81 79
      drupal_mail(
82 80
        'ldap_user',
......
106 104
 */
107 105
function _ldap_user_orphan_process_batch($ldap_user_conf, $batch, $user_count, $uids, $ldap_servers, $watchdogs_sids_missing_watchdogged, $query, $email_list) {
108 106
  $filters = [];
109
  $drupal_users = array();
107
  $drupal_users = [];
110 108
  /**
111 109
   * 1. populate $drupal_users[$sid][$puid_attr][$puid]['exists']  = TRUE
112 110
   *
......
114 112
   *       2nd batch   $i=50; $i<100; $i++
115 113
   *       4th batch   $i=150; $i<175; $i++
116 114
   */
117
  $start = ($batch - 1) * LDAP_SERVERS_MAXFILTER_ORS; // e.g 0, 50, 100
118
  $end_plus_1 = min(($batch) * LDAP_SERVERS_MAXFILTER_ORS, $user_count); // e.g. 50, 100, 150
119
  $batch_uids = array_slice($uids, $start, ($end_plus_1 - $start)); // e.g. 50, 50; 100, 50
115
  // e.g 0, 50, 100.
116
  $start = ($batch - 1) * LDAP_SERVERS_MAXFILTER_ORS;
117
  // e.g. 50, 100, 150.
118
  $end_plus_1 = min(($batch) * LDAP_SERVERS_MAXFILTER_ORS, $user_count);
119
  // e.g. 50, 50; 100, 50.
120
  $batch_uids = array_slice($uids, $start, ($end_plus_1 - $start));
120 121
  $accounts = entity_load('user', $batch_uids);
121 122

  
122 123
  foreach ($accounts as $uid => $user) {
......
134 135
      $drupal_users[$sid][$puid_attr][$puid]['exists'] = FALSE;
135 136
    }
136 137
    else {
137
      // user with missing ldap data fields
138
      // User with missing ldap data fields
138 139
      // perhaps should be watchdogged?
139 140
    }
140 141
  }
141 142

  
142
  //2. set $drupal_users[$sid][$puid_attr][$puid]['exists'] to FALSE
143
  // if entry doesn't exist
143
  // 2. set $drupal_users[$sid][$puid_attr][$puid]['exists'] to FALSE
144
  // if entry doesn't exist.
144 145
  foreach ($filters as $sid => $puid_attrs) {
145 146
    if (!isset($ldap_servers[$sid])) {
146 147
      if (!isset($watchdogs_sids_missing_watchdogged[$sid])) {
......
155 156
      continue;
156 157
    }
157 158
    foreach ($puid_attrs as $puid_attr => $ors) {
158
      // query should look like (|(guid=3243243)(guid=3243243)(guid=3243243))
159
      // Query should look like (|(guid=3243243)(guid=3243243)(guid=3243243))
159 160
      $ldap_filter = '(|' . join("", $ors) . ')';
160 161
      $ldap_entries = $ldap_servers[$sid]->searchAllBaseDns($ldap_filter, [$puid_attr]);
161 162
      if ($ldap_entries === FALSE) {
162
        unset($drupal_users[$sid]); // if query has error, don't remove ldap entries!
163
        // If query has error, don't remove ldap entries!
164
        unset($drupal_users[$sid]);
163 165
        watchdog(
164 166
          'ldap_user',
165 167
          'ldap server %sid had error while querying to
......
178 180
      }
179 181
    }
180 182
  }
181
  //3. we now have $drupal_users[$sid][$puid_attr][$puid]['exists'] = FALSE | TRUE;
182
  if ($ldap_user_conf->orphanedDrupalAcctBehavior == 'ldap_user_orphan_email') {
183
    global $base_url;
184
  }
183
  // 3. we now have $drupal_users[$sid][$puid_attr][$puid]['exists'] = bool.
184
  global $base_url;
185 185
  foreach ($drupal_users as $sid => $puid_x_puid_attrs) {
186 186
    foreach ($puid_x_puid_attrs as $puid_attr => $puids) {
187 187
      foreach ($puids as $puid => $user_data) {

Formats disponibles : Unified diff