You are here

function restful_token_auth_cron in RESTful 7

Same name and namespace in other branches
  1. 7.2 modules/restful_token_auth/restful_token_auth.module \restful_token_auth_cron()

Implements hook_cron().

Delete expired token auth entities.

File

modules/restful_token_auth/restful_token_auth.module, line 113
RESTful token authentication.

Code

function restful_token_auth_cron() {
  if (!variable_get('restful_token_auth_delete_expired_tokens', TRUE)) {

    // We should not delete expired tokens.
    return;
  }
  $query = new EntityFieldQuery();
  $result = $query
    ->entityCondition('entity_type', 'restful_token_auth')
    ->propertyCondition('expire', REQUEST_TIME, '<')
    ->range(0, 50)
    ->execute();
  if (empty($result['restful_token_auth'])) {

    // No expired tokens.
    return;
  }
  $ids = array_keys($result['restful_token_auth']);
  entity_delete_multiple('restful_token_auth', $ids);
}