1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* collection of functions related to removing user data
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
function ldap_severs_user_data_setup_batch($consumer_type = NULL) {
|
10 |
|
|
|
11 |
|
|
$max_uid = db_query("SELECT max(uid) FROM {users}")->fetchField();
|
12 |
|
|
$step = 100;
|
13 |
|
|
$operations = array();
|
14 |
|
|
for ($uid = 2; $uid <= $max_uid; $uid += $step) {
|
15 |
|
|
$operations[] = array("ldap_servers_empty_user_data", array($uid, $step, $consumer_type));
|
16 |
|
|
}
|
17 |
|
|
|
18 |
|
|
//put all that information into our batch array
|
19 |
|
|
return array(
|
20 |
|
|
'operations' => $operations,
|
21 |
|
|
'title' => t('Empty LDAP Authorization Data in user->data[ldap_authorizations][%consumer_id]', array('%consumer_id' => $consumer_type)),
|
22 |
|
|
'init_message' => t('Initializing'),
|
23 |
|
|
'error_message' => t('An error occurred'),
|
24 |
|
|
'finished' => t('Finished.')
|
25 |
|
|
);
|
26 |
|
|
|
27 |
|
|
}
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
/**
|
31 |
|
|
* function to remove $user->data['ldap_authorizations'] on uninstall
|
32 |
|
|
* which is called from ldap_authorization uninstall batches
|
33 |
|
|
*
|
34 |
|
|
*/
|
35 |
|
|
function ldap_servers_empty_user_data($start, $step, $consumer_type, &$context) {
|
36 |
|
|
|
37 |
|
|
$query = new EntityFieldQuery();
|
38 |
|
|
$query->entityCondition('entity_type', 'user')
|
39 |
|
|
->entityCondition('entity_id', array($start, $start + $step - 1), 'BETWEEN');
|
40 |
|
|
$results = $query->execute();
|
41 |
|
|
|
42 |
|
|
if (isset($results['user'])) {
|
43 |
|
|
foreach ($results['user'] as $uid => $entity_data) {
|
44 |
|
|
if ($uid > 1 && $account = user_load($uid, TRUE)) {
|
45 |
|
|
if ($consumer_type == NULL && isset($account->data['ldap_authorizations'])) { // remove all authorization data
|
46 |
|
|
$names[] = $account->name;
|
47 |
|
|
unset($account->data['ldap_authorizations']);
|
48 |
|
|
$updated_account = user_save($account, array('data' => $account->data));
|
49 |
|
|
}
|
50 |
|
|
elseif ($consumer_type != NULL && isset($account->data['ldap_authorizations'][$consumer_type])) { // remove only a particular consumers authorization data
|
51 |
|
|
unset($account->data['ldap_authorizations'][$consumer_type]);
|
52 |
|
|
$updated_account = user_save($account, array('data' => $account->data));
|
53 |
|
|
}
|
54 |
|
|
}
|
55 |
|
|
}
|
56 |
|
|
}
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
function ldap_authorization_generate_users() {
|
60 |
|
|
$response = "";
|
61 |
|
|
for ($i=1; $i<1000; $i++) {
|
62 |
|
|
$name = "user" . $i;
|
63 |
|
|
if ($account = user_load_by_name($name)) {
|
64 |
|
|
user_delete($account->uid);
|
65 |
|
|
}
|
66 |
|
|
$account = new stdClass();
|
67 |
|
|
$account->is_new = TRUE;
|
68 |
|
|
$account->name = "user" . $i;
|
69 |
|
|
$user_edit = array(
|
70 |
|
|
'data' => array('ldap_authorizations' => array('og_group' => 7, 'drupal_role' => 8))
|
71 |
|
|
);
|
72 |
|
|
|
73 |
|
|
$user_response = user_save($account, $user_edit);
|
74 |
|
|
$response .= $user_response->name . "<br/>";
|
75 |
|
|
}
|
76 |
|
|
return $response;
|
77 |
|
|
|
78 |
|
|
} |