You are here

function email_confirmer_cron in Email confirmer 8

Implements hook_cron().

1 string reference to 'email_confirmer_cron'
ultimate_cron.job.email_confirmer_cron.yml in config/optional/ultimate_cron.job.email_confirmer_cron.yml
config/optional/ultimate_cron.job.email_confirmer_cron.yml

File

./email_confirmer.module, line 27
Email confirmation API and service.

Code

function email_confirmer_cron() {

  // Purge old confirmations.
  $lifetime = \Drupal::config('email_confirmer.settings')
    ->get('confirmation_lifetime');
  if (empty($lifetime)) {

    // No purge.
    return;
  }
  $confirmation_storage = \Drupal::entityTypeManager()
    ->getStorage('email_confirmer_confirmation');
  $old_confirmations = $confirmation_storage
    ->getQuery()
    ->condition('created', \Drupal::time()
    ->getRequestTime() - $lifetime, '<')
    ->execute();
  if (!empty($old_confirmations)) {
    $confirmation_storage
      ->delete($confirmation_storage
      ->loadMultiple($old_confirmations));
    \Drupal::logger('email_confirmer')
      ->info('Purged @count old email confirmations.', [
      '@count' => count($old_confirmations),
    ]);
  }
}