You are here

private function OrphanProcessor::ldapQueryEligibleUser in Lightweight Directory Access Protocol (LDAP) 8.4

Same name and namespace in other branches
  1. 8.3 ldap_user/src/Processor/OrphanProcessor.php \Drupal\ldap_user\Processor\OrphanProcessor::ldapQueryEligibleUser()

Check eligible user against directory.

Parameters

int $uid: User ID.

string $serverId: Server ID.

string $persistentUidProperty: PUID Property.

string $persistentUid: PUID.

Return value

array Eligible user data.

1 call to OrphanProcessor::ldapQueryEligibleUser()
OrphanProcessor::batchQueryUsers in ldap_user/src/Processor/OrphanProcessor.php
Batch query for users.

File

ldap_user/src/Processor/OrphanProcessor.php, line 392

Class

OrphanProcessor
Locates potential orphan user accounts.

Namespace

Drupal\ldap_user\Processor

Code

private function ldapQueryEligibleUser(int $uid, string $serverId, string $persistentUidProperty, string $persistentUid) : array {
  $user['uid'] = $uid;
  $user['exists'] = FALSE;

  // Query LDAP and update the prepared users with the actual state.
  if (!isset($this->enabledServers[$serverId])) {
    if (!isset($this->missingServerSemaphore[$serverId])) {
      $this->logger
        ->error('Server %id not enabled, but needed to remove orphaned LDAP users', [
        '%id' => $serverId,
      ]);
      $this->missingServerSemaphore[$serverId] = TRUE;
    }
    return $user;
  }
  if ($this->enabledServers[$serverId]
    ->get('unique_persistent_attr_binary')) {
    $persistentUid = $this
      ->binaryFilter($persistentUid);
  }
  $this->ldapUserManager
    ->setServerById($serverId);
  $ldapEntries = $this->ldapUserManager
    ->searchAllBaseDns(sprintf('(%s=%s)', $persistentUidProperty, $persistentUid), [
    $persistentUidProperty,
  ]);
  if (!empty($ldapEntries)) {
    $user['exists'] = TRUE;
  }
  return $user;
}