You are here

function quotes_cron in Quotes 7

Same name and namespace in other branches
  1. 5 quotes.module \quotes_cron()
  2. 6 quotes.module \quotes_cron()

Implements hook_cron().

File

./quotes.module, line 1497
The quotes module allows users to maintain a list of quotes that can be displayed in any number of administrator-defined quote blocks.

Code

function quotes_cron() {
  $result = db_query("SELECT qb.* FROM {quotes_blocks} qb INNER JOIN {block} b ON b.module = 'quotes' WHERE b.status = 1 AND qb.cron_interval > 0 AND (qb.vid = 0 OR (qb.cron_last + (qb.cron_step * qb.cron_interval)) < :time)", array(
    ':time' => REQUEST_TIME,
  ));
  if ($result) {
    for ($updated = FALSE; $block = $result
      ->fetchAssoc(); $updated = TRUE) {
      $quotes = quotes_get_quote($block, TRUE, 1);
      db_update('quotes_blocks')
        ->fields(array(
        'vid' => $quotes[0],
        'cron_last' => REQUEST_TIME,
      ))
        ->condition('bid', $block['bid'])
        ->execute();
    }
    if ($updated) {
      cache_clear_all();
    }
  }
}