X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd7%2Fhook%2Fcron.twig;fp=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd7%2Fhook%2Fcron.twig;h=16e90ed4a5e1f4d2bbd1befaa6395c1f78aab6d1;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/chi-teck/drupal-code-generator/templates/d7/hook/cron.twig b/vendor/chi-teck/drupal-code-generator/templates/d7/hook/cron.twig new file mode 100644 index 000000000..16e90ed4a --- /dev/null +++ b/vendor/chi-teck/drupal-code-generator/templates/d7/hook/cron.twig @@ -0,0 +1,23 @@ +/** + * Implements hook_cron(). + */ +function {{ machine_name }}_cron() { + // Short-running operation example, not using a queue: + // Delete all expired records since the last cron run. + $expires = variable_get('mymodule_cron_last_run', REQUEST_TIME); + db_delete('mymodule_table') + ->condition('expires', $expires, '>=') + ->execute(); + variable_set('mymodule_cron_last_run', REQUEST_TIME); + + // Long-running operation example, leveraging a queue: + // Fetch feeds from other sites. + $result = db_query('SELECT * FROM {aggregator_feed} WHERE checked + refresh < :time AND refresh <> :never', array( + ':time' => REQUEST_TIME, + ':never' => AGGREGATOR_CLEAR_NEVER, + )); + $queue = DrupalQueue::get('aggregator_feeds'); + foreach ($result as $feed) { + $queue->createItem($feed); + } +}