1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Install, update and uninstall functions for the LDAP User module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_requirements().
|
10
|
*/
|
11
|
function ldap_user_requirements($phase) {
|
12
|
|
13
|
$requirements = [];
|
14
|
|
15
|
if ($phase == 'runtime') {
|
16
|
|
17
|
// Check for all $user->* fields created.
|
18
|
$missing_fields = ldap_user_update_check_user_fields(TRUE);
|
19
|
if (count($missing_fields)) {
|
20
|
$requirements['ldap_user']['title'] = t('User Fields for LDAP User Module Missing');
|
21
|
$requirements['ldap_user']['severity'] = REQUIREMENT_ERROR;
|
22
|
$requirements['ldap_user']['value'] = NULL;
|
23
|
|
24
|
$requirements['ldap_user']['description'] = t('Fields are added to the
|
25
|
Drupal User entity for LDAP User module functionality. These fields should
|
26
|
have been created in LDAP User update 7203. The following userfields are missing:') .
|
27
|
theme('item_list', [
|
28
|
'items' => $missing_fields,
|
29
|
'type' => 'ul',
|
30
|
'title' => NULL,
|
31
|
]) .
|
32
|
t('Rerun update 7203 to correct this; it will not write over destroy existing fields.');
|
33
|
}
|
34
|
}
|
35
|
|
36
|
// Check that ldapauth not installed.
|
37
|
return $requirements;
|
38
|
|
39
|
}
|
40
|
|
41
|
/**
|
42
|
* Implements hook_install().
|
43
|
*/
|
44
|
function ldap_user_install() {
|
45
|
|
46
|
foreach (ldap_user_user_entity_fields() as $field_id => $field_conf) {
|
47
|
$field_info = field_info_field($field_id);
|
48
|
if (!$field_info) {
|
49
|
field_create_field($field_conf['field']);
|
50
|
field_create_instance($field_conf['instance']);
|
51
|
}
|
52
|
}
|
53
|
|
54
|
// Make ldap user weight slightly less than other ldap modules so it can load
|
55
|
// user's associated ldap data first and save on ldap queries.
|
56
|
db_query("UPDATE {system} SET weight = -1 WHERE name = 'ldap_user'");
|
57
|
|
58
|
_ldap_user_install_update_authmap();
|
59
|
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
*
|
64
|
*/
|
65
|
function _ldap_user_install_update_authmap() {
|
66
|
db_update('authmap')
|
67
|
->fields(
|
68
|
[
|
69
|
'module' => 'ldap_user',
|
70
|
]
|
71
|
)
|
72
|
->condition('module', 'ldap_authentication')
|
73
|
->execute();
|
74
|
|
75
|
}
|
76
|
|
77
|
/**
|
78
|
* Implements hook_uninstall().
|
79
|
*/
|
80
|
function ldap_user_uninstall() {
|
81
|
|
82
|
foreach (ldap_user_user_entity_fields() as $field_id => $field_conf) {
|
83
|
|
84
|
$instance = field_info_instance($field_conf['instance']['entity_type'], $field_conf['instance']['field_name'], $field_conf['instance']['bundle']);
|
85
|
if ($instance) {
|
86
|
field_delete_instance($instance);
|
87
|
}
|
88
|
|
89
|
$field_info = field_info_field($field_conf['field']['field_name']);
|
90
|
if ($field_info) {
|
91
|
field_delete_field($field_conf['field']['field_name']);
|
92
|
}
|
93
|
}
|
94
|
|
95
|
variable_del('ldap_user_conf');
|
96
|
variable_del('ldap_user_cron_last_orphan_checked');
|
97
|
variable_del('ldap_user_cron_last_uid_checked');
|
98
|
|
99
|
}
|
100
|
|
101
|
/**
|
102
|
* Implements hook_schema().
|
103
|
*/
|
104
|
function ldap_user_schema() {
|
105
|
|
106
|
}
|
107
|
|
108
|
/**
|
109
|
* See http://api.drupal.org/api/drupal/modules%21field%21field.module/group/field/7.
|
110
|
*/
|
111
|
function ldap_user_user_entity_fields() {
|
112
|
|
113
|
$fields = [];
|
114
|
|
115
|
$field_name = 'ldap_user_puid_sid';
|
116
|
$fields[$field_name]['field'] = [
|
117
|
'field_name' => $field_name,
|
118
|
'type' => 'text',
|
119
|
'entity_types' => ['user'],
|
120
|
'cardinality' => 1,
|
121
|
'translatable' => 0,
|
122
|
'locked' => 1,
|
123
|
'module' => 'text',
|
124
|
'no_ui' => 1,
|
125
|
'settings' => [],
|
126
|
];
|
127
|
|
128
|
$fields[$field_name]['instance'] = [
|
129
|
'field_name' => $field_name,
|
130
|
'entity_type' => 'user',
|
131
|
'bundle' => 'user',
|
132
|
'label' => 'LDAP Server ID that puid was derived from. NULL if puid is independent of server configuration instance.',
|
133
|
'description' => 'This field should not be edited.',
|
134
|
'required' => 0,
|
135
|
'default_value' => [],
|
136
|
'settings' => [
|
137
|
'text_processing' => 0,
|
138
|
],
|
139
|
'widget' => [
|
140
|
'type' => 'ldap_user_hidden',
|
141
|
'settings' => [],
|
142
|
'module' => 'ldap_user',
|
143
|
],
|
144
|
'display' => [
|
145
|
'default' => [
|
146
|
'label' => 'hidden',
|
147
|
'type' => 'hidden',
|
148
|
],
|
149
|
'full' => [
|
150
|
'label' => 'hidden',
|
151
|
'type' => 'hidden',
|
152
|
],
|
153
|
'teaser' => [
|
154
|
'label' => 'hidden',
|
155
|
'type' => 'hidden',
|
156
|
],
|
157
|
],
|
158
|
];
|
159
|
|
160
|
$field_name = 'ldap_user_puid';
|
161
|
$fields[$field_name]['field'] = [
|
162
|
'field_name' => $field_name,
|
163
|
'type' => 'text',
|
164
|
'entity_types' => ['user'],
|
165
|
'cardinality' => 1,
|
166
|
'translatable' => 0,
|
167
|
'locked' => 1,
|
168
|
'module' => 'text',
|
169
|
'no_ui' => 1,
|
170
|
'settings' => [],
|
171
|
];
|
172
|
|
173
|
$fields[$field_name]['instance'] = [
|
174
|
'field_name' => $field_name,
|
175
|
'entity_type' => 'user',
|
176
|
'bundle' => 'user',
|
177
|
'label' => 'Value of user\'s permanent unique id. This should never change for a given ldap identified user.',
|
178
|
'description' => 'This field should not be edited.',
|
179
|
'required' => 0,
|
180
|
'default_value' => [],
|
181
|
'settings' => [
|
182
|
'text_processing' => 0,
|
183
|
],
|
184
|
'widget' => [
|
185
|
'type' => 'ldap_user_hidden',
|
186
|
'settings' => [],
|
187
|
'module' => 'ldap_user',
|
188
|
],
|
189
|
'display' => [
|
190
|
'default' => [
|
191
|
'label' => 'hidden',
|
192
|
'type' => 'hidden',
|
193
|
],
|
194
|
'full' => [
|
195
|
'label' => 'hidden',
|
196
|
'type' => 'hidden',
|
197
|
],
|
198
|
'teaser' => [
|
199
|
'label' => 'hidden',
|
200
|
'type' => 'hidden',
|
201
|
],
|
202
|
],
|
203
|
];
|
204
|
|
205
|
$field_name = 'ldap_user_puid_property';
|
206
|
$fields[$field_name]['field'] = [
|
207
|
'field_name' => $field_name,
|
208
|
'type' => 'text',
|
209
|
'entity_types' => ['user'],
|
210
|
'cardinality' => 1,
|
211
|
'translatable' => 0,
|
212
|
'locked' => 1,
|
213
|
'module' => 'text',
|
214
|
'no_ui' => 1,
|
215
|
'settings' => [],
|
216
|
];
|
217
|
|
218
|
$fields[$field_name]['instance'] = [
|
219
|
'field_name' => $field_name,
|
220
|
'entity_type' => 'user',
|
221
|
'bundle' => 'user',
|
222
|
'label' => 'Property specified as user\'s puid.',
|
223
|
'description' => 'This field should not be edited.',
|
224
|
'required' => 0,
|
225
|
'default_value' => [],
|
226
|
'settings' => [
|
227
|
'text_processing' => 0,
|
228
|
],
|
229
|
'widget' => [
|
230
|
'type' => 'ldap_user_hidden',
|
231
|
'settings' => [],
|
232
|
'module' => 'ldap_user',
|
233
|
],
|
234
|
'display' => [
|
235
|
'default' => [
|
236
|
'label' => 'hidden',
|
237
|
'type' => 'hidden',
|
238
|
],
|
239
|
'full' => [
|
240
|
'label' => 'hidden',
|
241
|
'type' => 'hidden',
|
242
|
],
|
243
|
'teaser' => [
|
244
|
'label' => 'hidden',
|
245
|
'type' => 'hidden',
|
246
|
],
|
247
|
],
|
248
|
];
|
249
|
|
250
|
$field_name = 'ldap_user_current_dn';
|
251
|
$fields[$field_name]['field'] = [
|
252
|
'field_name' => $field_name,
|
253
|
'type' => 'text',
|
254
|
'entity_types' => ['user'],
|
255
|
'cardinality' => 1,
|
256
|
'translatable' => 0,
|
257
|
'locked' => 1,
|
258
|
'module' => 'text',
|
259
|
'no_ui' => 1,
|
260
|
'settings' => [],
|
261
|
];
|
262
|
|
263
|
$fields[$field_name]['instance'] = [
|
264
|
'field_name' => $field_name,
|
265
|
'entity_type' => 'user',
|
266
|
'bundle' => 'user',
|
267
|
'label' => 'User LDAP DN',
|
268
|
'description' => 'May change when user\'s DN changes. This field should not be edited.',
|
269
|
'required' => 0,
|
270
|
'default_value' => [],
|
271
|
'settings' => [
|
272
|
'text_processing' => 0,
|
273
|
],
|
274
|
'widget' => [
|
275
|
'type' => 'ldap_user_hidden',
|
276
|
'settings' => [],
|
277
|
'module' => 'ldap_user',
|
278
|
],
|
279
|
'display' => [
|
280
|
'default' => [
|
281
|
'label' => 'hidden',
|
282
|
'type' => 'hidden',
|
283
|
],
|
284
|
'full' => [
|
285
|
'label' => 'hidden',
|
286
|
'type' => 'hidden',
|
287
|
],
|
288
|
'teaser' => [
|
289
|
'label' => 'hidden',
|
290
|
'type' => 'hidden',
|
291
|
],
|
292
|
],
|
293
|
];
|
294
|
|
295
|
$field_name = 'ldap_user_prov_entries';
|
296
|
$fields[$field_name]['field'] = [
|
297
|
'field_name' => $field_name,
|
298
|
'type' => 'text',
|
299
|
'entity_types' => ['user'],
|
300
|
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
|
301
|
'translatable' => 0,
|
302
|
'locked' => 1,
|
303
|
'module' => 'text',
|
304
|
'no_ui' => 1,
|
305
|
'settings' => [],
|
306
|
];
|
307
|
|
308
|
$fields[$field_name]['instance'] = [
|
309
|
'field_name' => $field_name,
|
310
|
'entity_type' => 'user',
|
311
|
'bundle' => 'user',
|
312
|
'label' => 'LDAP Entries that have been provisioned from this Drupal user.',
|
313
|
'description' => 'This field should not be edited.',
|
314
|
'required' => 0,
|
315
|
'default_value' => NULL,
|
316
|
'settings' => [
|
317
|
'text_processing' => 0,
|
318
|
],
|
319
|
'widget' => [
|
320
|
'type' => 'ldap_user_hidden',
|
321
|
'settings' => [],
|
322
|
'module' => 'ldap_user',
|
323
|
],
|
324
|
'display' => [
|
325
|
'default' => [
|
326
|
'label' => 'hidden',
|
327
|
'type' => 'hidden',
|
328
|
],
|
329
|
'full' => [
|
330
|
'label' => 'hidden',
|
331
|
'type' => 'hidden',
|
332
|
],
|
333
|
'teaser' => [
|
334
|
'label' => 'hidden',
|
335
|
'type' => 'hidden',
|
336
|
],
|
337
|
],
|
338
|
];
|
339
|
|
340
|
$field_name = 'ldap_user_last_checked';
|
341
|
$fields[$field_name]['field'] = [
|
342
|
'field_name' => $field_name,
|
343
|
'type' => 'number_integer',
|
344
|
'entity_types' => ['user'],
|
345
|
'cardinality' => 1,
|
346
|
'translatable' => 0,
|
347
|
'locked' => 1,
|
348
|
'module' => 'number',
|
349
|
'no_ui' => 1,
|
350
|
'settings' => [],
|
351
|
];
|
352
|
|
353
|
$fields[$field_name]['instance'] = [
|
354
|
'field_name' => $field_name,
|
355
|
'entity_type' => 'user',
|
356
|
'bundle' => 'user',
|
357
|
'label' => 'Unix timestamp of when Drupal user was compard to ldap entry. This could be for purposes of synching, deleteing drupal account, etc.',
|
358
|
'description' => 'This field should not be edited.',
|
359
|
'required' => 0,
|
360
|
'default_value' => NULL,
|
361
|
'settings' => [],
|
362
|
'widget' => [
|
363
|
'type' => 'ldap_user_hidden',
|
364
|
'settings' => [],
|
365
|
'module' => 'ldap_user',
|
366
|
],
|
367
|
'display' => [
|
368
|
'default' => [
|
369
|
'label' => 'hidden',
|
370
|
'type' => 'hidden',
|
371
|
],
|
372
|
'full' => [
|
373
|
'label' => 'hidden',
|
374
|
'type' => 'hidden',
|
375
|
],
|
376
|
'teaser' => [
|
377
|
'label' => 'hidden',
|
378
|
'type' => 'hidden',
|
379
|
],
|
380
|
],
|
381
|
];
|
382
|
|
383
|
$field_name = 'ldap_user_ldap_exclude';
|
384
|
$fields[$field_name]['field'] = [
|
385
|
'field_name' => $field_name,
|
386
|
'type' => 'number_integer',
|
387
|
'entity_types' => ['user'],
|
388
|
'cardinality' => 1,
|
389
|
'translatable' => 0,
|
390
|
'locked' => 1,
|
391
|
'module' => 'number',
|
392
|
'no_ui' => 1,
|
393
|
'settings' => [],
|
394
|
];
|
395
|
|
396
|
$fields[$field_name]['instance'] = [
|
397
|
'field_name' => $field_name,
|
398
|
'entity_type' => 'user',
|
399
|
'bundle' => 'user',
|
400
|
'label' => 'Whether to exclude the user from LDAP functionality',
|
401
|
'description' => 'This field should not be edited.',
|
402
|
'required' => 0,
|
403
|
'default_value' => 0,
|
404
|
'settings' => [],
|
405
|
'widget' => [
|
406
|
'type' => 'ldap_user_hidden',
|
407
|
'settings' => [],
|
408
|
'module' => 'ldap_user',
|
409
|
],
|
410
|
'display' => [
|
411
|
'default' => [
|
412
|
'label' => 'hidden',
|
413
|
'type' => 'hidden',
|
414
|
],
|
415
|
'full' => [
|
416
|
'label' => 'hidden',
|
417
|
'type' => 'hidden',
|
418
|
],
|
419
|
'teaser' => [
|
420
|
'label' => 'hidden',
|
421
|
'type' => 'hidden',
|
422
|
],
|
423
|
],
|
424
|
];
|
425
|
|
426
|
return $fields;
|
427
|
}
|
428
|
|
429
|
/**
|
430
|
* Update authmap table, changing ldap_authentication to ldap_user, disable ldap_profile.
|
431
|
*/
|
432
|
function ldap_user_update_7201() {
|
433
|
if (module_exists('ldap_profile')) {
|
434
|
module_disable(['ldap_profile', TRUE]);
|
435
|
}
|
436
|
_ldap_user_install_update_authmap();
|
437
|
}
|
438
|
|
439
|
/**
|
440
|
* Attach ldap_user_last_checked field to user entity to track reconciliation of ldap and drupal accounts.
|
441
|
*/
|
442
|
function ldap_user_update_7202() {
|
443
|
|
444
|
return t('ldap_user_last_checked field added to user entity.');
|
445
|
|
446
|
}
|
447
|
|
448
|
/**
|
449
|
* Make sure all user entity fields are created.
|
450
|
*/
|
451
|
function ldap_user_update_7203() {
|
452
|
|
453
|
if (module_exists('ldap_groups')) {
|
454
|
module_disable(['ldap_groups', TRUE]);
|
455
|
}
|
456
|
|
457
|
$fields_added = ldap_user_update_check_user_fields();
|
458
|
|
459
|
if (count($fields_added)) {
|
460
|
$fields = join(', ', $fields_added);
|
461
|
return t('%fields added to user entity.', ['%fields' => $fields]);
|
462
|
}
|
463
|
else {
|
464
|
return t('no fields needed to be added to user entity.');
|
465
|
}
|
466
|
|
467
|
}
|
468
|
|
469
|
/**
|
470
|
* Make sure all user entity field instances are created.
|
471
|
*/
|
472
|
function ldap_user_update_7204() {
|
473
|
|
474
|
$fields_added = ldap_user_update_check_user_fields();
|
475
|
|
476
|
if (count($fields_added)) {
|
477
|
$fields = join(', ', $fields_added);
|
478
|
return t('%fields added to user entity.', ['%fields' => $fields]);
|
479
|
}
|
480
|
else {
|
481
|
return t('no fields needed to be added to user entity.');
|
482
|
}
|
483
|
|
484
|
}
|
485
|
|
486
|
/**
|
487
|
* Make sure all user entity field instances are created.
|
488
|
*/
|
489
|
function ldap_user_update_7205() {
|
490
|
|
491
|
return ldap_user_update_7204();
|
492
|
|
493
|
}
|
494
|
|
495
|
/**
|
496
|
*
|
497
|
*/
|
498
|
function ldap_user_update_check_user_fields($query = FALSE) {
|
499
|
if (!$query) {
|
500
|
module_enable(['number']);
|
501
|
}
|
502
|
$fields_added = [];
|
503
|
foreach (ldap_user_user_entity_fields() as $field_id => $field_conf) {
|
504
|
$field_info = field_info_field($field_id);
|
505
|
if (!$field_info) {
|
506
|
$fields_added[] = $field_id;
|
507
|
if (!$query) {
|
508
|
field_create_field($field_conf['field']);
|
509
|
}
|
510
|
}
|
511
|
$field_instance_info = field_info_instance('user', $field_id, 'user');
|
512
|
if (!$field_instance_info) {
|
513
|
$fields_added[] = $field_id . " instance";
|
514
|
if (!$query) {
|
515
|
field_create_instance($field_conf['instance']);
|
516
|
}
|
517
|
}
|
518
|
}
|
519
|
return $fields_added;
|
520
|
|
521
|
}
|
522
|
|
523
|
/**
|
524
|
* Set an appropriate default value for accountsWithSameEmail.
|
525
|
*/
|
526
|
function ldap_user_update_7206() {
|
527
|
$message = NULL;
|
528
|
$ldap_user_conf = ldap_user_conf('admin', TRUE);
|
529
|
// If the configuration variable is not set, set a reasonable default and
|
530
|
// advise the administrator.
|
531
|
if (module_exists('sharedemail')) {
|
532
|
$message = t('The module "sharedemail" was detected. LDAP User configuration has been set so that user accounts can be provisioned regardless of whether an existing user account has the same email address.');
|
533
|
$ldap_user_conf->accountsWithSameEmail = LDAP_USER_ACCOUNTS_WITH_SAME_EMAIL_ENABLED;
|
534
|
}
|
535
|
else {
|
536
|
// The "sharedemail" module is not enabled; do not enable this setting.
|
537
|
// Do not mention anything in the hook_update_N output.
|
538
|
$ldap_user_conf->accountsWithSameEmail = LDAP_USER_ACCOUNTS_WITH_SAME_EMAIL_DISABLED;
|
539
|
}
|
540
|
$ldap_user_conf->save();
|
541
|
|
542
|
return $message;
|
543
|
}
|