You are here

ldap_authorization.install in Lightweight Directory Access Protocol (LDAP) 7.2

Install, update and uninstall functions for the LDAP authorization module.

File

ldap_authorization/ldap_authorization.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the LDAP authorization module.
 */

/**
 * Implements hook_requirements().
 */
function ldap_authorization_requirements($phase) {
  $requirements = [];
  if ($phase != "install" && db_field_exists('ldapauth', 'ldapgroups_in_dn')) {
    $requirements['ldap_authorization_ldap_integration']['title'] = t('LDAP Integration LDAP Groups Upgrade Concern');
    $requirements['ldap_authorization_ldap_integration']['severity'] = REQUIREMENT_WARNING;
    $requirements['ldap_authorization_ldap_integration']['value'] = NULL;
    $requirements['ldap_authorization_ldap_integration']['description'] = t('Upgrade from Drupal 6 LDAP Groups to Drupal 7
      LDAP Authorization is not automatic.  LDAP Authorization will need to be configured by hand.
      The authorization options are different and automated updgrade is not possible.
      See also. See http://drupal.org/node/1023016, http://drupal.org/node/1183192.
      This message will go away when the ldapauth database table is removed.');
  }

  // Check that ldapauth not installed.
  return $requirements;
}

/**
 * Implements hook_install().
 */
function ldap_authorization_install() {
  cache_clear_all('field_info_types:', 'cache_field', TRUE);
  foreach (ldap_authorization_user_entity_fields() as $field_id => $field_conf) {
    $field_info = field_info_field($field_id);
    if (!$field_info) {
      field_create_field($field_conf['field']);
      field_create_instance($field_conf['instance']);
    }
  }
}

/**
 * Implements hook_uninstall().
 */
function ldap_authorization_uninstall() {
  foreach (ldap_authorization_user_entity_fields() as $field_id => $field_conf) {
    $instance = field_info_instance($field_conf['instance']['entity_type'], $field_conf['instance']['field_name'], $field_conf['instance']['bundle']);
    if ($instance) {
      field_delete_instance($instance);
    }
    $field_info = field_info_field($field_conf['field']['field_name']);
    if ($field_info) {
      field_delete_field($field_conf['field']['field_name']);
    }
  }
  module_load_include('inc', 'ldap_servers', 'ldap_servers.user_data_remove');
  batch_set(ldap_severs_user_data_setup_batch());
  $batch =& batch_get();
}

/**
 *
 */
function ldap_authorization_user_entity_fields() {
  $fields = [];
  return $fields;
}

/**
 * Implements hook_schema().
 */
function ldap_authorization_schema() {
  $schema['ldap_authorization'] = [
    'export' => [
      'key' => 'consumer_type',
      'key name' => 'Mapping ID',
      'identifier' => 'consumer_type',
      'primary key' => 'numeric_consumer_conf_id',
      'api' => [
        'owner' => 'ldap_authorization',
        'api' => 'ldap_authorization',
        'minimum_version' => 1,
        'current_version' => 1,
      ],
    ],
    'description' => "Data used to map users ldap entry to authorization rights.",
    'primary key' => [
      'numeric_consumer_conf_id',
    ],
    'foreign keys' => [
      'sid' => [
        'table' => 'ldap_servers',
        'columns' => [
          'sid' => 'sid',
        ],
      ],
    ],
  ];
  module_load_include('inc', 'ldap_servers', 'ldap_servers.functions');
  module_load_include('php', 'ldap_authorization', 'LdapAuthorizationConsumerConfAdmin.class');
  $fields = LdapAuthorizationConsumerConfAdmin::fields();
  foreach ($fields as $name => $props) {
    if (isset($props['schema'])) {
      $schema['ldap_authorization']['fields'][$name] = $props['schema'];
    }
  }
  return $schema;
}

/**
 * Add 'create_consumers field to ldap_authorization table.
 */
function ldap_authorization_update_7100() {
  if (!db_field_exists('ldap_authorization', 'create_consumers')) {
    db_add_field('ldap_authorization', 'create_consumers', [
      'type' => 'int',
      'size' => 'tiny',
      'not null' => TRUE,
      'default' => 0,
    ]);
    return t('"create_consumers" field added to ldap_authorization table');
  }
  else {
    return t('No database changes made.');
  }
}

/**
 * Add derive_from_attr_use_first_attr field to ldap_authorization table.
 */
function ldap_authorization_update_7101() {
  if (!db_field_exists('ldap_authorization', 'derive_from_attr_use_first_attr')) {
    db_add_field('ldap_authorization', 'derive_from_attr_use_first_attr', [
      'type' => 'int',
      'size' => 'tiny',
      'not null' => TRUE,
      'default' => 0,
    ]);
    return t('"derive_from_attr_use_first_attr" field added to ldap_authorization table');
  }
  else {
    return t('No database changes made.');
  }
}

/**
 * Add derive_from_entry_search_all column to ldap_authorization.
 */
function ldap_authorization_update_7102() {
  if (!db_field_exists('ldap_authorization', 'derive_from_entry_search_all')) {
    db_add_field('ldap_authorization', 'derive_from_entry_search_all', [
      'type' => 'int',
      'size' => 'tiny',
      'not null' => TRUE,
      'default' => 0,
    ]);
    return t('"derive_from_entry_search_all" field added to ldap_authorization table');
  }
  else {
    return t('No database changes made.');
  }
}

/**
 * Change derive_from_attr_attr and derive_from_entry fields to text instead of varchar 2555.
 */
function ldap_authorization_update_7103() {
  foreach ([
    'derive_from_dn_attr',
    'derive_from_attr_attr',
    'derive_from_entry_entries',
  ] as $field_name) {
    db_change_field('ldap_authorization', $field_name, $field_name, [
      'type' => 'text',
      'not null' => FALSE,
    ]);
  }
}

/**
 * Change derive_from_attr_attr and derive_from_entry fields to text instead of varchar 2555
 * applied second time because beta6 and 7 were wrong.
 */
function ldap_authorization_update_7104() {
  foreach ([
    'derive_from_dn_attr',
    'derive_from_attr_attr',
    'derive_from_entry_entries',
  ] as $field_name) {
    db_change_field('ldap_authorization', $field_name, $field_name, [
      'type' => 'text',
      'not null' => FALSE,
    ]);
  }
}

/**
 * Add derive_from_entry_user_ldap_attr field to allow user specification of dn or other identifier.
 */
function ldap_authorization_update_7105() {
  if (!db_field_exists('ldap_authorization', 'derive_from_entry_user_ldap_attr')) {
    db_add_field('ldap_authorization', 'derive_from_entry_user_ldap_attr', [
      'type' => 'varchar',
      'length' => 255,
      'default' => NULL,
    ]);
    return t('"derive_from_entry_user_ldap_attr" field added to ldap_authorization table');
  }
  else {
    return t('No database changes made.');
  }
}

/**
 * Add nested checkboxes to derive from entry and attributes strategies.
 */
function ldap_authorization_update_7106() {
  if (!db_field_exists('ldap_authorization', 'derive_from_attr_nested')) {
    db_add_field('ldap_authorization', 'derive_from_attr_nested', [
      'type' => 'int',
      'size' => 'tiny',
      'not null' => TRUE,
      'default' => 0,
    ]);
    $msg = t('"derive_from_attr_nested" field added to ldap_authorization table');
  }
  if (!db_field_exists('ldap_authorization', 'derive_from_entry_nested')) {
    db_add_field('ldap_authorization', 'derive_from_entry_nested', [
      'type' => 'int',
      'size' => 'tiny',
      'not null' => TRUE,
      'default' => 0,
    ]);
    $msg .= t('"derive_from_entry_nested" field added to ldap_authorization table');
  }
  return $msg ? $msg : t('No database changes made.');
}

/**
 * Add derive_from_entry_use_first_attr field to and remove description field from ldap_authorization table.
 */
function ldap_authorization_update_7107() {
  $changes = '';
  if (!db_field_exists('ldap_authorization', 'derive_from_entry_use_first_attr')) {
    db_add_field('ldap_authorization', 'derive_from_entry_use_first_attr', [
      'type' => 'int',
      'size' => 'tiny',
      'not null' => TRUE,
      'default' => 0,
    ]);
    $changes .= t('"derive_from_entry_use_first_attr" field added to ldap_authorization table');
  }
  if (db_field_exists('ldap_authorization', 'description')) {
    db_drop_field('ldap_authorization', 'description');
    $changes .= t('"description" field dropped from to ldap_authorization table');
  }
  return $changes ? $changes : t('No database changes made.');
}

/**
 * Add derive_from_entry_entries_attr field to allow user specification of attribute representing group in queries.
 */
function ldap_authorization_update_7108() {
  if (!db_field_exists('ldap_authorization', 'derive_from_entry_entries_attr')) {
    db_add_field('ldap_authorization', 'derive_from_entry_entries_attr', [
      'type' => 'varchar',
      'length' => 255,
      'default' => NULL,
    ]);
    return t('"derive_from_entry_entries_attr" field added to ldap_authorization table');
  }
  else {
    return t('No database changes made.');
  }
  _ldap_authorization_add_ldap_user_fields();
}

/**
 * Moving some groups related fields into ldap server module.
 */
function ldap_authorization_update_7201() {

  // Need to merge 2 table fields (derive_from_entry_use_first_attr and derive_from_attr_use_first_attr into one field useFirstAttrAsGroupId)
  $results = '';
  if (!db_field_exists('ldap_authorization', 'useFirstAttrAsGroupId')) {
    db_add_field('ldap_authorization', 'useFirstAttrAsGroupId', [
      'type' => 'int',
      'size' => tiny,
      'not null' => TRUE,
      'default' => 0,
    ]);
    $results .= t('"useFirstAttrAsGroupId" field added to ldap_authorization table');
  }
  if (!db_field_exists('ldap_authorization', 'searchAll')) {
    db_add_field('ldap_authorization', 'searchAll', [
      'type' => 'int',
      'size' => tiny,
      'not null' => TRUE,
      'default' => 0,
    ]);
    $results .= t('"searchAll" field added to ldap_authorization table');
  }
}

/**
 * Remove user ldap authorizations field.  its in $user->data now.
 */
function ldap_authorization_update_7202() {
  $instance = [
    'field_name' => 'ldap_authorizations',
    'entity_type' => 'user',
    'bundle' => 'user',
  ];
  field_delete_instance($instance, TRUE);
  field_delete_field('ldap_authorizations');
}

/**
 * Make all schema field names lowercase in ldap server to deal with cronic case sensitivity issues.
 */
function ldap_authorization_update_7203() {
  if (db_field_exists('ldap_authorization', 'searchAll')) {
    db_drop_field('ldap_authorization', 'searchAll');
  }
  $schema = ldap_authorization_schema();
  $field_schema = $schema['ldap_authorization']['fields']['use_first_attr_as_groupid'];
  if (db_field_exists('ldap_authorization', 'useFirstAttrAsGroupId')) {
    if (db_field_exists('ldap_authorization', 'use_first_attr_as_groupid')) {
      db_drop_field('ldap_authorization', 'useFirstAttrAsGroupId');
    }
    else {
      db_change_field('ldap_authorization', 'useFirstAttrAsGroupId', 'use_first_attr_as_groupid', $field_schema);
    }
  }
}

/**
 * Make all schema field names lowercase in ldap server to deal with cronic case sensitivity issues.
 */
function ldap_authorization_update_7204() {
  $schema = ldap_authorization_schema();
  $field_schema = $schema['ldap_authorization']['fields']['mappings'];
  if (db_field_exists('ldap_authorization', 'mappings')) {
    db_change_field('ldap_authorization', 'mappings', 'mappings', $field_schema);
  }
}

Functions

Namesort descending Description
ldap_authorization_install Implements hook_install().
ldap_authorization_requirements Implements hook_requirements().
ldap_authorization_schema Implements hook_schema().
ldap_authorization_uninstall Implements hook_uninstall().
ldap_authorization_update_7100 Add 'create_consumers field to ldap_authorization table.
ldap_authorization_update_7101 Add derive_from_attr_use_first_attr field to ldap_authorization table.
ldap_authorization_update_7102 Add derive_from_entry_search_all column to ldap_authorization.
ldap_authorization_update_7103 Change derive_from_attr_attr and derive_from_entry fields to text instead of varchar 2555.
ldap_authorization_update_7104 Change derive_from_attr_attr and derive_from_entry fields to text instead of varchar 2555 applied second time because beta6 and 7 were wrong.
ldap_authorization_update_7105 Add derive_from_entry_user_ldap_attr field to allow user specification of dn or other identifier.
ldap_authorization_update_7106 Add nested checkboxes to derive from entry and attributes strategies.
ldap_authorization_update_7107 Add derive_from_entry_use_first_attr field to and remove description field from ldap_authorization table.
ldap_authorization_update_7108 Add derive_from_entry_entries_attr field to allow user specification of attribute representing group in queries.
ldap_authorization_update_7201 Moving some groups related fields into ldap server module.
ldap_authorization_update_7202 Remove user ldap authorizations field. its in $user->data now.
ldap_authorization_update_7203 Make all schema field names lowercase in ldap server to deal with cronic case sensitivity issues.
ldap_authorization_update_7204 Make all schema field names lowercase in ldap server to deal with cronic case sensitivity issues.
ldap_authorization_user_entity_fields