annotate vendor/chi-teck/drupal-code-generator/templates/d7/hook/cron.twig @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents c75dbcec494b
children
rev   line source
Chris@0 1 /**
Chris@0 2 * Implements hook_cron().
Chris@0 3 */
Chris@0 4 function {{ machine_name }}_cron() {
Chris@0 5 // Short-running operation example, not using a queue:
Chris@0 6 // Delete all expired records since the last cron run.
Chris@0 7 $expires = variable_get('mymodule_cron_last_run', REQUEST_TIME);
Chris@0 8 db_delete('mymodule_table')
Chris@0 9 ->condition('expires', $expires, '>=')
Chris@0 10 ->execute();
Chris@0 11 variable_set('mymodule_cron_last_run', REQUEST_TIME);
Chris@0 12
Chris@0 13 // Long-running operation example, leveraging a queue:
Chris@0 14 // Fetch feeds from other sites.
Chris@0 15 $result = db_query('SELECT * FROM {aggregator_feed} WHERE checked + refresh < :time AND refresh <> :never', array(
Chris@0 16 ':time' => REQUEST_TIME,
Chris@0 17 ':never' => AGGREGATOR_CLEAR_NEVER,
Chris@0 18 ));
Chris@0 19 $queue = DrupalQueue::get('aggregator_feeds');
Chris@0 20 foreach ($result as $feed) {
Chris@0 21 $queue->createItem($feed);
Chris@0 22 }
Chris@0 23 }