You are here

function simple_oauth_cron in Simple OAuth (OAuth2) & OpenID Connect 5.x

Same name and namespace in other branches
  1. 8.4 simple_oauth.module \simple_oauth_cron()
  2. 8 simple_oauth.module \simple_oauth_cron()
  3. 8.2 simple_oauth.module \simple_oauth_cron()
  4. 8.3 simple_oauth.module \simple_oauth_cron()

Implements hook_cron().

File

./simple_oauth.module, line 23
Contains simple_oauth.module.

Code

function simple_oauth_cron() {

  /** @var \Drupal\simple_oauth\ExpiredCollector $collector */
  $collector = \Drupal::service('simple_oauth.expired_collector');
  $config = \Drupal::config('simple_oauth.settings');
  $logger = \Drupal::logger('simple_oauth');
  $token_cron_batch_size = $config
    ->get('token_cron_batch_size');

  // Deleting one batch of expired tokens.
  if (!empty($expired_tokens = $collector
    ->collect($token_cron_batch_size))) {
    $collector
      ->deleteMultipleTokens($expired_tokens);
    $logger
      ->notice('Deleted @limit expired tokens in cron.', [
      '@limit' => $token_cron_batch_size,
    ]);
  }
}