You are here

private function LdapEntryProvisionSubscriber::updateUserProvisioningReferences in Lightweight Directory Access Protocol (LDAP) 8.4

Save provisioning entries to database.

Need to store <sid>|<dn> in ldap_user_prov_entries field, which may contain more than one.

Parameters

\Symfony\Component\Ldap\Entry $entry: LDAP Entry.

1 call to LdapEntryProvisionSubscriber::updateUserProvisioningReferences()
LdapEntryProvisionSubscriber::provisionLdapEntry in ldap_user/src/EventSubscriber/LdapEntryProvisionSubscriber.php
Provision an LDAP entry if none exists.

File

ldap_user/src/EventSubscriber/LdapEntryProvisionSubscriber.php, line 560

Class

LdapEntryProvisionSubscriber
Event subscribers for creating and updating LDAP entries.

Namespace

Drupal\ldap_user\EventSubscriber

Code

private function updateUserProvisioningReferences(Entry $entry) : void {
  $ldap_user_prov_entry = $this->ldapServer
    ->id() . '|' . $entry
    ->getDn();
  if ($this->account
    ->get('ldap_user_prov_entries') !== NULL) {
    $this->account
      ->set('ldap_user_prov_entries', []);
  }
  $ldap_user_provisioning_entry_exists = FALSE;
  if ($this->account
    ->get('ldap_user_prov_entries')->value) {
    foreach ($this->account
      ->get('ldap_user_prov_entries')->value as $field_value_instance) {
      if ($field_value_instance === $ldap_user_prov_entry) {
        $ldap_user_provisioning_entry_exists = TRUE;
      }
    }
  }
  if (!$ldap_user_provisioning_entry_exists) {
    $prov_entries = $this->account
      ->get('ldap_user_prov_entries')->value;
    $prov_entries[] = [
      'value' => $ldap_user_prov_entry,
      'format' => NULL,
      'save_value' => $ldap_user_prov_entry,
    ];
    $this->account
      ->set('ldap_user_prov_entries', $prov_entries);
    $this->account
      ->save();
  }
}