You are here

function ldap_user_update_8307 in Lightweight Directory Access Protocol (LDAP) 8.4

Same name and namespace in other branches
  1. 8.3 ldap_user/ldap_user.install \ldap_user_update_8307()

Converts unreadable integers to strings for LDAP provision triggers.

File

ldap_user/ldap_user.install, line 208

Code

function ldap_user_update_8307() {
  $config_factory = \Drupal::configFactory();
  $config = $config_factory
    ->getEditable('ldap_user.settings');
  switch ($config
    ->get('acctCreation')) {
    case 1:
      $value = LdapUserAttributesInterface::ACCOUNT_CREATION_USER_SETTINGS_FOR_LDAP;
      break;
    default:
    case 4:
      $value = LdapUserAttributesInterface::ACCOUNT_CREATION_LDAP_BEHAVIOUR;
      break;
  }
  $config
    ->set('acctCreation', $value);
  switch ($config
    ->get('userConflictResolve')) {
    case 1:
      $value = LdapUserAttributesInterface::USER_CONFLICT_LOG;
      break;
    default:
    case 2:
      $value = LdapUserAttributesInterface::USER_CONFLICT_ATTEMPT_RESOLVE;
      break;
  }
  $config
    ->set('userConflictResolve', $value);
  switch ($config
    ->get('manualAccountConflict')) {
    case 1:
      $value = LdapUserAttributesInterface::MANUAL_ACCOUNT_CONFLICT_REJECT;
      break;
    case 2:
      $value = LdapUserAttributesInterface::MANUAL_ACCOUNT_CONFLICT_LDAP_ASSOCIATE;
      break;
    case 3:
      $value = LdapUserAttributesInterface::MANUAL_ACCOUNT_CONFLICT_SHOW_OPTION_ON_FORM;
      break;
    default:
    case 4:
      $value = LdapUserAttributesInterface::MANUAL_ACCOUNT_CONFLICT_NO_LDAP_ASSOCIATE;
      break;
  }
  $config
    ->set('manualAccountConflict', $value);
  $syncMappings = $config
    ->get('ldapUserSyncMappings');
  foreach ($syncMappings as $direction => $data) {
    foreach ($data as $key => $mapping) {
      $events = [];
      foreach ($mapping['prov_events'] as $provEvent) {
        switch ($provEvent) {
          case 1:
            $events[] = LdapUserAttributesInterface::EVENT_CREATE_DRUPAL_USER;
            break;
          case 2:
            $events[] = LdapUserAttributesInterface::EVENT_SYNC_TO_DRUPAL_USER;
            break;
          case 3:
            $events[] = LdapUserAttributesInterface::EVENT_CREATE_LDAP_ENTRY;
            break;
          case 4:
            $events[] = LdapUserAttributesInterface::EVENT_SYNC_TO_LDAP_ENTRY;
            break;
          case 5:
            $events[] = LdapUserAttributesInterface::EVENT_LDAP_ASSOCIATE_DRUPAL_USER;
            break;
        }
      }
      $syncMappings[$direction][$key]['prov_events'] = $events;
    }
  }
  $config
    ->set('ldapUserSyncMappings', $syncMappings);
  $config
    ->save();
}