Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ldap / ldap_servers / ldap_servers.user_data_remove.inc @ bc175c27

1
<?php
2

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

    
8
function ldap_severs_user_data_setup_batch($consumer_type = NULL) {
9

    
10
  $max_uid = db_query("SELECT max(uid) FROM {users}")->fetchField();
11
  $step = 100;
12
  $operations = array();
13
  for ($uid = 2; $uid <= $max_uid; $uid += $step) {
14
    $operations[] = array("ldap_servers_empty_user_data", array($uid, $step, $consumer_type));
15
  }
16
   
17
  //put all that information into our batch array
18
  return array(
19
    'operations' => $operations,
20
    'title' => t('Empty LDAP Authorization Data in user->data[ldap_authorizations][%consumer_id]', array('%consumer_id' => $consumer_type)),
21
    'init_message' => t('Initializing'),
22
    'error_message' => t('An error occurred'),
23
    'finished' => t('Finished.')
24
  );
25
  
26
}
27

    
28

    
29
/**
30
 * function to remove $user->data['ldap_authorizations'] on uninstall
31
 * which is called from ldap_authorization uninstall batches
32
 *
33
 */
34
function ldap_servers_empty_user_data($start, $step, $consumer_type, &$context) { 
35
  
36
  $query = new EntityFieldQuery();
37
  $query->entityCondition('entity_type', 'user')
38
    ->entityCondition('entity_id', array($start, $start + $step - 1), 'BETWEEN');
39
  $results = $query->execute();
40

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

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