Projet

Général

Profil

Paste
Télécharger (10,9 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ldap / ldap_authorization / ldap_authorization.install @ 91af538d

1 85ad3d82 Assos Assos
<?php
2
3
/**
4
 * @file
5
 * Install, update and uninstall functions for the LDAP authorization module.
6
 */
7
8
/**
9
 * Implements hook_requirements().
10
 */
11
function ldap_authorization_requirements($phase) {
12 32700c57 Assos Assos
  $requirements = [];
13 85ad3d82 Assos Assos
14 bc175c27 Assos Assos
  if ($phase != "install" && db_field_exists('ldapauth', 'ldapgroups_in_dn')) {
15 85ad3d82 Assos Assos
    $requirements['ldap_authorization_ldap_integration']['title'] = t('LDAP Integration LDAP Groups Upgrade Concern');
16
    $requirements['ldap_authorization_ldap_integration']['severity'] = REQUIREMENT_WARNING;
17
    $requirements['ldap_authorization_ldap_integration']['value'] = NULL;
18
    $requirements['ldap_authorization_ldap_integration']['description'] = t('Upgrade from Drupal 6 LDAP Groups to Drupal 7
19
      LDAP Authorization is not automatic.  LDAP Authorization will need to be configured by hand.
20
      The authorization options are different and automated updgrade is not possible.
21
      See also. See http://drupal.org/node/1023016, http://drupal.org/node/1183192.
22
      This message will go away when the ldapauth database table is removed.');
23
  }
24 bc175c27 Assos Assos
  // Check that ldapauth not installed.
25 85ad3d82 Assos Assos
  return $requirements;
26
}
27
28
/**
29
 * Implements hook_install().
30
 */
31
function ldap_authorization_install() {
32
33
  cache_clear_all('field_info_types:', 'cache_field', TRUE);
34
  foreach (ldap_authorization_user_entity_fields() as $field_id => $field_conf) {
35
    $field_info = field_info_field($field_id);
36
    if (!$field_info) {
37
      field_create_field($field_conf['field']);
38
      field_create_instance($field_conf['instance']);
39
    }
40
  }
41
42
}
43
44
/**
45
 * Implements hook_uninstall().
46
 */
47
function ldap_authorization_uninstall() {
48
  foreach (ldap_authorization_user_entity_fields() as $field_id => $field_conf) {
49
50
    $instance = field_info_instance($field_conf['instance']['entity_type'], $field_conf['instance']['field_name'], $field_conf['instance']['bundle']);
51
    if ($instance) {
52
      field_delete_instance($instance);
53
    }
54
55
    $field_info = field_info_field($field_conf['field']['field_name']);
56
    if ($field_info) {
57
      field_delete_field($field_conf['field']['field_name']);
58
    }
59
  }
60
  module_load_include('inc', 'ldap_servers', 'ldap_servers.user_data_remove');
61
  batch_set(ldap_severs_user_data_setup_batch());
62
  $batch =& batch_get();
63
64 bc175c27 Assos Assos
}
65 85ad3d82 Assos Assos
66 bc175c27 Assos Assos
/**
67
 *
68
 */
69 85ad3d82 Assos Assos
function ldap_authorization_user_entity_fields() {
70
71 32700c57 Assos Assos
  $fields = [];
72 85ad3d82 Assos Assos
73
  return $fields;
74
}
75
76
/**
77
 * Implements hook_schema().
78
 */
79
function ldap_authorization_schema() {
80
81 32700c57 Assos Assos
  $schema['ldap_authorization'] = [
82
    'export' => [
83 85ad3d82 Assos Assos
      'key' => 'consumer_type',
84
      'key name' => 'Mapping ID',
85
      'identifier' => 'consumer_type',
86
      'primary key' => 'numeric_consumer_conf_id',
87 32700c57 Assos Assos
      'api' => [
88 85ad3d82 Assos Assos
        'owner' => 'ldap_authorization',
89
        'api' => 'ldap_authorization',
90
        'minimum_version' => 1,
91
        'current_version' => 1,
92 32700c57 Assos Assos
      ],
93
    ],
94 85ad3d82 Assos Assos
95
    'description' => "Data used to map users ldap entry to authorization rights.",
96 32700c57 Assos Assos
    'primary key' => ['numeric_consumer_conf_id'],
97
    'foreign keys' => [
98
      'sid' => [
99 85ad3d82 Assos Assos
        'table' => 'ldap_servers',
100 32700c57 Assos Assos
        'columns' => ['sid' => 'sid'],
101
      ],
102
    ],
103
  ];
104 85ad3d82 Assos Assos
105
  module_load_include('inc', 'ldap_servers', 'ldap_servers.functions');
106
  module_load_include('php', 'ldap_authorization', 'LdapAuthorizationConsumerConfAdmin.class');
107
108
  $fields = LdapAuthorizationConsumerConfAdmin::fields();
109
  foreach ($fields as $name => $props) {
110
    if (isset($props['schema'])) {
111
      $schema['ldap_authorization']['fields'][$name] = $props['schema'];
112
    }
113
  }
114
115
  return $schema;
116
}
117
118
/**
119 bc175c27 Assos Assos
 * Add 'create_consumers field to ldap_authorization table.
120 85ad3d82 Assos Assos
 */
121
function ldap_authorization_update_7100() {
122
123
  if (!db_field_exists('ldap_authorization', 'create_consumers')) {
124 32700c57 Assos Assos
    db_add_field('ldap_authorization', 'create_consumers', [
125 85ad3d82 Assos Assos
      'type' => 'int',
126
      'size' => 'tiny',
127
      'not null' => TRUE,
128
      'default' => 0,
129 32700c57 Assos Assos
    ]);
130 85ad3d82 Assos Assos
    return t('"create_consumers" field added to ldap_authorization table');
131
  }
132
  else {
133
    return t('No database changes made.');
134
  }
135
136
}
137
138
/**
139 bc175c27 Assos Assos
 * Add derive_from_attr_use_first_attr field to ldap_authorization table.
140 85ad3d82 Assos Assos
 */
141
function ldap_authorization_update_7101() {
142
143
  if (!db_field_exists('ldap_authorization', 'derive_from_attr_use_first_attr')) {
144 32700c57 Assos Assos
    db_add_field('ldap_authorization', 'derive_from_attr_use_first_attr', [
145 85ad3d82 Assos Assos
      'type' => 'int',
146
      'size' => 'tiny',
147
      'not null' => TRUE,
148
      'default' => 0,
149 32700c57 Assos Assos
    ]);
150 85ad3d82 Assos Assos
    return t('"derive_from_attr_use_first_attr" field added to ldap_authorization table');
151
  }
152
  else {
153
    return t('No database changes made.');
154
  }
155
156
}
157
158
/**
159 bc175c27 Assos Assos
 * Add derive_from_entry_search_all column to ldap_authorization.
160 85ad3d82 Assos Assos
 */
161
function ldap_authorization_update_7102() {
162
163
  if (!db_field_exists('ldap_authorization', 'derive_from_entry_search_all')) {
164 32700c57 Assos Assos
    db_add_field('ldap_authorization', 'derive_from_entry_search_all', [
165 85ad3d82 Assos Assos
      'type' => 'int',
166
      'size' => 'tiny',
167
      'not null' => TRUE,
168
      'default' => 0,
169 32700c57 Assos Assos
    ]);
170 85ad3d82 Assos Assos
    return t('"derive_from_entry_search_all" field added to ldap_authorization table');
171
  }
172
  else {
173
    return t('No database changes made.');
174
  }
175
176
}
177
178
/**
179 bc175c27 Assos Assos
 * Change derive_from_attr_attr and derive_from_entry fields to text instead of varchar 2555.
180 85ad3d82 Assos Assos
 */
181
function ldap_authorization_update_7103() {
182
183 32700c57 Assos Assos
  foreach (['derive_from_dn_attr', 'derive_from_attr_attr', 'derive_from_entry_entries'] as $field_name) {
184
    db_change_field('ldap_authorization', $field_name, $field_name, [
185 bc175c27 Assos Assos
      'type' => 'text',
186
      'not null' => FALSE,
187 32700c57 Assos Assos
    ]);
188 85ad3d82 Assos Assos
  }
189
190
}
191
192
/**
193 bc175c27 Assos Assos
 * Change derive_from_attr_attr and derive_from_entry fields to text instead of varchar 2555
194 85ad3d82 Assos Assos
 * applied second time because beta6 and 7 were wrong.
195
 */
196
function ldap_authorization_update_7104() {
197
198 32700c57 Assos Assos
  foreach (['derive_from_dn_attr', 'derive_from_attr_attr', 'derive_from_entry_entries'] as $field_name) {
199
    db_change_field('ldap_authorization', $field_name, $field_name, [
200 bc175c27 Assos Assos
      'type' => 'text',
201
      'not null' => FALSE,
202 32700c57 Assos Assos
    ]);
203 85ad3d82 Assos Assos
  }
204
205
}
206
207
/**
208 bc175c27 Assos Assos
 * Add derive_from_entry_user_ldap_attr field to allow user specification of dn or other identifier.
209 85ad3d82 Assos Assos
 */
210
function ldap_authorization_update_7105() {
211
212
  if (!db_field_exists('ldap_authorization', 'derive_from_entry_user_ldap_attr')) {
213 32700c57 Assos Assos
    db_add_field('ldap_authorization', 'derive_from_entry_user_ldap_attr', [
214 85ad3d82 Assos Assos
      'type' => 'varchar',
215
      'length' => 255,
216
      'default' => NULL,
217 32700c57 Assos Assos
    ]);
218 85ad3d82 Assos Assos
    return t('"derive_from_entry_user_ldap_attr" field added to ldap_authorization table');
219
  }
220
  else {
221
    return t('No database changes made.');
222
  }
223
224
}
225
226
/**
227 bc175c27 Assos Assos
 * Add nested checkboxes to derive from entry and attributes strategies.
228 85ad3d82 Assos Assos
 */
229
function ldap_authorization_update_7106() {
230
231
  if (!db_field_exists('ldap_authorization', 'derive_from_attr_nested')) {
232 32700c57 Assos Assos
    db_add_field('ldap_authorization', 'derive_from_attr_nested', [
233 85ad3d82 Assos Assos
      'type' => 'int',
234
      'size' => 'tiny',
235
      'not null' => TRUE,
236
      'default' => 0,
237 32700c57 Assos Assos
    ]);
238 85ad3d82 Assos Assos
    $msg = t('"derive_from_attr_nested" field added to ldap_authorization table');
239
  }
240
241
  if (!db_field_exists('ldap_authorization', 'derive_from_entry_nested')) {
242 32700c57 Assos Assos
    db_add_field('ldap_authorization', 'derive_from_entry_nested', [
243 85ad3d82 Assos Assos
      'type' => 'int',
244
      'size' => 'tiny',
245
      'not null' => TRUE,
246
      'default' => 0,
247 32700c57 Assos Assos
    ]);
248 bc175c27 Assos Assos
    $msg .= t('"derive_from_entry_nested" field added to ldap_authorization table');
249 85ad3d82 Assos Assos
  }
250
251 bc175c27 Assos Assos
  return ($msg) ? $msg : t('No database changes made.');
252 85ad3d82 Assos Assos
}
253
254
/**
255 bc175c27 Assos Assos
 * Add derive_from_entry_use_first_attr field to and remove description field from ldap_authorization table.
256 85ad3d82 Assos Assos
 */
257
function ldap_authorization_update_7107() {
258
259
  $changes = '';
260
261
  if (!db_field_exists('ldap_authorization', 'derive_from_entry_use_first_attr')) {
262 32700c57 Assos Assos
    db_add_field('ldap_authorization', 'derive_from_entry_use_first_attr', [
263 85ad3d82 Assos Assos
      'type' => 'int',
264
      'size' => 'tiny',
265
      'not null' => TRUE,
266
      'default' => 0,
267 32700c57 Assos Assos
    ]);
268 85ad3d82 Assos Assos
    $changes .= t('"derive_from_entry_use_first_attr" field added to ldap_authorization table');
269
  }
270
271
  if (db_field_exists('ldap_authorization', 'description')) {
272
    db_drop_field('ldap_authorization', 'description');
273 bc175c27 Assos Assos
    $changes .= t('"description" field dropped from to ldap_authorization table');
274 85ad3d82 Assos Assos
  }
275
276
  return ($changes) ? $changes : t('No database changes made.');
277
278
}
279
280
/**
281 bc175c27 Assos Assos
 * Add derive_from_entry_entries_attr field to allow user specification of attribute representing group in queries.
282 85ad3d82 Assos Assos
 */
283
function ldap_authorization_update_7108() {
284
285
  if (!db_field_exists('ldap_authorization', 'derive_from_entry_entries_attr')) {
286 32700c57 Assos Assos
    db_add_field('ldap_authorization', 'derive_from_entry_entries_attr', [
287 85ad3d82 Assos Assos
      'type' => 'varchar',
288
      'length' => 255,
289
      'default' => NULL,
290 32700c57 Assos Assos
    ]);
291 85ad3d82 Assos Assos
    return t('"derive_from_entry_entries_attr" field added to ldap_authorization table');
292
  }
293
  else {
294
    return t('No database changes made.');
295
  }
296
  _ldap_authorization_add_ldap_user_fields();
297
298
}
299
300
/**
301 bc175c27 Assos Assos
 * Moving some groups related fields into ldap server module.
302 85ad3d82 Assos Assos
 */
303
function ldap_authorization_update_7201() {
304
305 bc175c27 Assos Assos
  // Need to merge 2 table fields (derive_from_entry_use_first_attr and derive_from_attr_use_first_attr into one field useFirstAttrAsGroupId)
306 85ad3d82 Assos Assos
  $results = '';
307
308
  if (!db_field_exists('ldap_authorization', 'useFirstAttrAsGroupId')) {
309 32700c57 Assos Assos
    db_add_field('ldap_authorization', 'useFirstAttrAsGroupId', [
310 85ad3d82 Assos Assos
      'type' => 'int',
311
      'size' => tiny,
312
      'not null' => TRUE,
313
      'default' => 0,
314 32700c57 Assos Assos
    ]);
315 85ad3d82 Assos Assos
    $results .= t('"useFirstAttrAsGroupId" field added to ldap_authorization table');
316
  }
317
318
  if (!db_field_exists('ldap_authorization', 'searchAll')) {
319 32700c57 Assos Assos
    db_add_field('ldap_authorization', 'searchAll', [
320 85ad3d82 Assos Assos
      'type' => 'int',
321
      'size' => tiny,
322
      'not null' => TRUE,
323
      'default' => 0,
324 32700c57 Assos Assos
    ]);
325 85ad3d82 Assos Assos
    $results .= t('"searchAll" field added to ldap_authorization table');
326
  }
327
}
328
329
/**
330 bc175c27 Assos Assos
 * Remove user ldap authorizations field.  its in $user->data now.
331 85ad3d82 Assos Assos
 */
332
function ldap_authorization_update_7202() {
333
334 32700c57 Assos Assos
  $instance = [
335 bc175c27 Assos Assos
    'field_name' => 'ldap_authorizations',
336
    'entity_type' => 'user',
337
    'bundle' => 'user',
338 32700c57 Assos Assos
  ];
339 bc175c27 Assos Assos
  field_delete_instance($instance, TRUE);
340
  field_delete_field('ldap_authorizations');
341 85ad3d82 Assos Assos
342
}
343
344
/**
345 bc175c27 Assos Assos
 * Make all schema field names lowercase in ldap server to deal with cronic case sensitivity issues.
346 85ad3d82 Assos Assos
 */
347
function ldap_authorization_update_7203() {
348
349
  if (db_field_exists('ldap_authorization', 'searchAll')) {
350
    db_drop_field('ldap_authorization', 'searchAll');
351
  }
352
353
  $schema = ldap_authorization_schema();
354
  $field_schema = $schema['ldap_authorization']['fields']['use_first_attr_as_groupid'];
355
  if (db_field_exists('ldap_authorization', 'useFirstAttrAsGroupId')) {
356
    if (db_field_exists('ldap_authorization', 'use_first_attr_as_groupid')) {
357
      db_drop_field('ldap_authorization', 'useFirstAttrAsGroupId');
358
    }
359
    else {
360
      db_change_field('ldap_authorization', 'useFirstAttrAsGroupId', 'use_first_attr_as_groupid', $field_schema);
361
    }
362
  }
363
364
}
365
366
/**
367 bc175c27 Assos Assos
 * Make all schema field names lowercase in ldap server to deal with cronic case sensitivity issues.
368 85ad3d82 Assos Assos
 */
369
function ldap_authorization_update_7204() {
370
371
  $schema = ldap_authorization_schema();
372
  $field_schema = $schema['ldap_authorization']['fields']['mappings'];
373
  if (db_field_exists('ldap_authorization', 'mappings')) {
374 bc175c27 Assos Assos
    db_change_field('ldap_authorization', 'mappings', 'mappings', $field_schema);
375 85ad3d82 Assos Assos
  }
376
377
}