You are here

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

Process one user.

Parameters

array $users: User to process.

1 call to OrphanProcessor::processOrphanedAccounts()
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 327

Class

OrphanProcessor
Locates potential orphan user accounts.

Namespace

Drupal\ldap_user\Processor

Code

private function processOrphanedAccounts(array $users) : void {
  foreach ($users as $user) {
    if (isset($user['uid']) && $user['exists'] === FALSE) {

      /** @var \Drupal\user\Entity\User $account */
      $account = $this->entityTypeManager
        ->getStorage('user')
        ->load($user['uid']);
      $method = $this->configLdapUser
        ->get('orphanedDrupalAcctBehavior');
      switch ($method) {
        case 'ldap_user_orphan_email':
          $link = Url::fromRoute('entity.user.edit_form', [
            'user' => $user['uid'],
          ])
            ->setAbsolute();
          $this->emailList[] = $account
            ->getAccountName() . ',' . $account
            ->getEmail() . ',' . $link
            ->toString();
          break;
        case 'user_cancel_block':
        case 'user_cancel_block_unpublish':
        case 'user_cancel_reassign':
        case 'user_cancel_delete':
          $this->emailList[] = $account
            ->getAccountName() . ',' . $account
            ->getEmail();
          $this
            ->cancelUser($account, $method);
          break;
      }
    }
  }
}