You are here

function node_authlink_cron in Node authorize link 7

Same name and namespace in other branches
  1. 8 node_authlink.module \node_authlink_cron()

Implements hook_cron().

File

./node_authlink.module, line 287
Provides functionality for the node_authlink module.

Code

function node_authlink_cron() {
  $node_types = node_type_get_types();
  foreach ($node_types as $type) {
    $expire = variable_get('node_authlink_expire_' . $type->type, 0);
    if (!$expire) {
      continue;
    }

    // NIDs of expired keys.
    $query = db_select('node', 'n');
    $query
      ->leftJoin('node_authlink_nodes', 'a', 'n.nid = a.nid');
    $query
      ->fields('n', array(
      'nid',
    ))
      ->condition('n.type', $type->type)
      ->condition('a.created', time() - $expire, '<');
    $nids = $query
      ->execute()
      ->fetchCol();

    // Regenerate keys.
    foreach ($nids as $nid) {
      db_delete('node_authlink_nodes')
        ->condition('nid', $nid)
        ->execute();
      node_authlink_node_insert($nid);
      if (module_exists('entitycache')) {
        cache_clear_all($nid, 'cache_entity_node');
      }
    }
  }
}