function node_authlink_cron in Node authorize link 8
Same name and namespace in other branches
- 7 node_authlink.module \node_authlink_cron()
Implementation of hook_cron().
File
- ./
node_authlink.module, line 399 - Node Authlink hooks and alters.
Code
function node_authlink_cron() {
$node_types = \Drupal\node\Entity\NodeType::loadMultiple();
$config = \Drupal::config('node_authlink.settings');
foreach ($node_types as $type) {
$expire = $config
->get('expire.' . $type
->id());
if (!$expire) {
continue;
}
// NIDs of expired keys
$query = \Drupal::database()
->select('node', 'n');
$query
->leftJoin('node_authlink_nodes', 'a', 'n.nid = a.nid');
$query
->fields('n', [
'nid',
])
->condition('n.type', $type
->id())
->condition('a.created', time() - $expire, '<');
$nids = $query
->execute()
->fetchCol();
// Regenerate keys
foreach ($nids as $nid) {
\Drupal::database()
->delete('node_authlink_nodes')
->condition('nid', $nid)
->execute();
node_authlink_create($nid);
}
}
}