You are here

private function OrphanProcessor::fetchUidsToCheck 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::fetchUidsToCheck()

Fetch UIDs to check.

Return value

array All relevant UID.

1 call to OrphanProcessor::fetchUidsToCheck()
OrphanProcessor::checkOrphans in ldap_user/src/Processor/OrphanProcessor.php
Check for Drupal accounts which no longer have a related LDAP entry.

File

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

Class

OrphanProcessor
Locates potential orphan user accounts.

Namespace

Drupal\ldap_user\Processor

Code

private function fetchUidsToCheck() : array {

  // We want to query Drupal accounts, which are LDAP associated where a DN
  // is present. The lastUidChecked is used to process only a limited number
  // of batches in the cron run and each user is only checked if the time
  // configured for checking has lapsed.
  $lastUidChecked = $this->state
    ->get('ldap_user_cron_last_uid_checked', 1);
  $query = $this->entityTypeManager
    ->getStorage('user')
    ->getQuery()
    ->accessCheck(FALSE)
    ->exists('ldap_user_current_dn')
    ->exists('ldap_user_puid_property')
    ->exists('ldap_user_puid_sid')
    ->exists('ldap_user_puid')
    ->condition('uid', $lastUidChecked, '>')
    ->condition('status', 1)
    ->sort('uid')
    ->range(0, $this->configLdapUser
    ->get('orphanedCheckQty'));
  $group = $query
    ->orConditionGroup();
  $group
    ->notExists('ldap_user_last_checked');
  switch ($this->configLdapUser
    ->get('orphanedAccountCheckInterval')) {
    case 'always':
      $group
        ->condition('ldap_user_last_checked', time(), '<');
      break;
    case 'daily':
      $group
        ->condition('ldap_user_last_checked', strtotime('today'), '<');
      break;
    case 'weekly':
    default:
      $group
        ->condition('ldap_user_last_checked', strtotime('today - 7 days'), '<');
      break;
    case 'monthly':
      $group
        ->condition('ldap_user_last_checked', strtotime('today - 30 days'), '<');
      break;
  }
  $query
    ->condition($group);
  $uids = $query
    ->execute();
  if (count($uids) < $this->configLdapUser
    ->get('orphanedCheckQty')) {
    $this->state
      ->set('ldap_user_cron_last_uid_checked', 1);
  }
  else {
    $this->state
      ->set('ldap_user_cron_last_uid_checked', max($uids));
  }
  return $uids;
}