Projet

Général

Profil

Paste
Télécharger (14,1 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ldap / ldap_user / ldap_user.install @ bc175c27

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