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_servers/ldap_servers.user_data_remove.inc
1 1
<?php
2 2

  
3 3
/**
4
* @file
5
* collection of functions related to removing user data
6
*/
4
 * @file
5
 * Collection of functions related to removing user data.
6
 */
7 7

  
8
/**
9
 *
10
 */
8 11
function ldap_severs_user_data_setup_batch($consumer_type = NULL) {
9 12

  
10 13
  $max_uid = db_query("SELECT max(uid) FROM {users}")->fetchField();
11 14
  $step = 100;
12
  $operations = array();
15
  $operations = [];
13 16
  for ($uid = 2; $uid <= $max_uid; $uid += $step) {
14
    $operations[] = array("ldap_servers_empty_user_data", array($uid, $step, $consumer_type));
17
    $operations[] = ["ldap_servers_empty_user_data", [$uid, $step, $consumer_type]];
15 18
  }
16
   
17
  //put all that information into our batch array
18
  return array(
19

  
20
  // Put all that information into our batch array.
21
  return [
19 22
    'operations' => $operations,
20
    'title' => t('Empty LDAP Authorization Data in user->data[ldap_authorizations][%consumer_id]', array('%consumer_id' => $consumer_type)),
23
    'title' => t('Empty LDAP Authorization Data in user->data[ldap_authorizations][%consumer_id]', ['%consumer_id' => $consumer_type]),
21 24
    'init_message' => t('Initializing'),
22 25
    'error_message' => t('An error occurred'),
23
    'finished' => t('Finished.')
24
  );
25
  
26
}
26
    'finished' => t('Finished.'),
27
  ];
27 28

  
29
}
28 30

  
29 31
/**
30
 * function to remove $user->data['ldap_authorizations'] on uninstall
31
 * which is called from ldap_authorization uninstall batches
32
 *
32
 * Function to remove $user->data['ldap_authorizations'] on uninstall
33
 * which is called from ldap_authorization uninstall batches.
33 34
 */
34
function ldap_servers_empty_user_data($start, $step, $consumer_type, &$context) { 
35
  
35
function ldap_servers_empty_user_data($start, $step, $consumer_type, &$context) {
36

  
36 37
  $query = new EntityFieldQuery();
37 38
  $query->entityCondition('entity_type', 'user')
38
    ->entityCondition('entity_id', array($start, $start + $step - 1), 'BETWEEN');
39
    ->entityCondition('entity_id', [$start, $start + $step - 1], 'BETWEEN');
39 40
  $results = $query->execute();
40 41

  
41 42
  if (isset($results['user'])) {
42 43
    foreach ($results['user'] as $uid => $entity_data) {
43 44
      if ($uid > 1 && $account = user_load($uid, TRUE)) {
44
        if ($consumer_type == NULL && isset($account->data['ldap_authorizations'])) { // remove all authorization data
45
        // Remove all authorization data.
46
        if ($consumer_type == NULL && isset($account->data['ldap_authorizations'])) {
45 47
          $names[] = $account->name;
46 48
          unset($account->data['ldap_authorizations']);
47
          $updated_account = user_save($account, array('data' => $account->data));
49
          $updated_account = user_save($account, ['data' => $account->data]);
48 50
        }
49
        elseif ($consumer_type != NULL && isset($account->data['ldap_authorizations'][$consumer_type])) { // remove only a particular consumers authorization data
51
        // Remove only a particular consumers authorization data.
52
        elseif ($consumer_type != NULL && isset($account->data['ldap_authorizations'][$consumer_type])) {
50 53
          unset($account->data['ldap_authorizations'][$consumer_type]);
51
          $updated_account = user_save($account, array('data' => $account->data));
54
          $updated_account = user_save($account, ['data' => $account->data]);
52 55
        }
53 56
      }
54 57
    }
55 58
  }
56 59
}
57 60

  
61
/**
62
 *
63
 */
58 64
function ldap_authorization_generate_users() {
59 65
  $response = "";
60 66
  for ($i = 1; $i < 1000; $i++) {
......
65 71
    $account = new stdClass();
66 72
    $account->is_new = TRUE;
67 73
    $account->name = "user" . $i;
68
    $user_edit = array(
69
      'data' => array('ldap_authorizations' => array('og_group' => 7, 'drupal_role' => 8))
70
    );
71
    
74
    $user_edit = [
75
      'data' => ['ldap_authorizations' => ['og_group' => 7, 'drupal_role' => 8]],
76
    ];
77

  
72 78
    $user_response = user_save($account, $user_edit);
73 79
    $response .= $user_response->name . "<br/>";
74 80
  }
75 81
  return $response;
76
  
82

  
77 83
}

Formats disponibles : Unified diff