public function OrphanProcessor::checkOrphans in Lightweight Directory Access Protocol (LDAP) 8.4
Same name and namespace in other branches
- 8.3 ldap_user/src/Processor/OrphanProcessor.php \Drupal\ldap_user\Processor\OrphanProcessor::checkOrphans()
Check for Drupal accounts which no longer have a related LDAP entry.
File
- ldap_user/
src/ Processor/ OrphanProcessor.php, line 150
Class
- OrphanProcessor
- Locates potential orphan user accounts.
Namespace
Drupal\ldap_user\ProcessorCode
public function checkOrphans() : void {
$orphan_policy = $this->configLdapUser
->get('orphanedDrupalAcctBehavior');
if (!$orphan_policy || $orphan_policy === 'ldap_user_orphan_do_not_check') {
return;
}
$uids = $this
->fetchUidsToCheck();
if (!empty($uids)) {
// To avoid query limits, queries are batched by the limit, for example
// with 175 users and a limit of 30, 6 batches are run.
$batches = floor(count($uids) / $this->ldapQueryOrLimit) + 1;
$batchResults = [];
for ($batch = 1; $batch <= $batches; $batch++) {
$batchResults[] = $this
->batchQueryUsers($batch, $uids);
}
$this
->processOrphanedAccounts(array_merge(...$batchResults));
if (count($this->emailList) > 0) {
$this
->sendOrphanedAccountsMail();
}
}
else {
// This can happen if you update all users periodically and saving them
// has caused all 'ldap_user_last_checked' values to be newer than your
// interval.
$this->logger
->notice('No eligible accounts founds for orphan account verification.');
}
}