You are here

function access_unpublished_cron in Access unpublished 8

Implements hook_cron().

File

./access_unpublished.module, line 73
Contains access_unpublished implementations.

Code

function access_unpublished_cron() {
  $config = \Drupal::config('access_unpublished.settings');
  if ($config
    ->get('cleanup_expired_tokens')) {
    $strtotime = strtotime($config
      ->get('cleanup_expired_tokens_period'));

    /** @var \Drupal\access_unpublished\AccessTokenManager $tokenManager */
    $tokenManager = \Drupal::service('access_unpublished.access_token_manager');
    foreach ($tokenManager
      ->getAccessTokens('expired') as $token) {
      if ($strtotime > $token
        ->get('expire')->value) {
        $token
          ->delete();
      }
    }
  }
}