You are here

public function UserEmailVerification::cronHandler in User email verification 8

Handle cron related tasks.

Overrides UserEmailVerificationInterface::cronHandler

File

src/UserEmailVerification.php, line 330

Class

UserEmailVerification
User email verification helper service.

Namespace

Drupal\user_email_verification

Code

public function cronHandler() {
  $reminder_interval = $this
    ->getReminderInterval();

  // Select those that need to be blocked.
  $uids = $this
    ->getVerificationUidsFor('block_account', $reminder_interval);
  if ($uids) {
    $queue = $this->queue
      ->get('user_email_verification_block_account');
    $uids = array_chunk($uids, UserEmailVerificationInterface::QUEUE_BLOCK_ACCOUNT_LIMIT);
    foreach ($uids as $uids_chunk) {
      $queue
        ->createItem($uids_chunk);
    }
  }

  // Select those that need to be sent a reminder.
  $uids = $this
    ->getVerificationUidsFor('reminders', $reminder_interval);
  if ($uids) {
    $queue = $this->queue
      ->get('user_email_verification_reminders');
    $uids = array_chunk($uids, UserEmailVerificationInterface::QUEUE_REMINDERS_LIMIT);
    foreach ($uids as $uids_chunk) {
      $queue
        ->createItem($uids_chunk);
    }
  }
  if ($this
    ->isExtendedPeriodEnabled()) {

    // Delete accounts which have not verified their Email addresses within
    // extended time period. Similar to blocking users, but don't care about
    // reminder settings. Select those that need to be blocked.
    $uids = $this
      ->getVerificationUidsFor('delete_account', $this
      ->getExtendedValidateInterval());
    if ($uids) {
      $queue = $this->queue
        ->get('user_email_verification_delete_account');
      $uids = array_chunk($uids, UserEmailVerificationInterface::QUEUE_DELETE_ACCOUNT_LIMIT);
      foreach ($uids as $uids_chunk) {
        $queue
          ->createItem($uids_chunk);
      }
    }
  }
}