You are here

function sharedblocks_cron in Shared Blocks 6

Same name and namespace in other branches
  1. 7 sharedblocks.module \sharedblocks_cron()

Implementation of hook_cron().

File

./sharedblocks.module, line 96

Code

function sharedblocks_cron() {

  // Check to see if any shared blocks have expired
  $r = db_query('SELECT id, description, url, block_data, update_interval FROM {sharedblocks} WHERE expiration < %d', time());
  while ($row = db_fetch_array($r)) {

    // If so, grab a new copy of the block data from the url.
    $block_data = sharedblocks_fetch_block($row['url']);
    if ($block_data) {
      $record['block_data'] = serialize($block_data);
      watchdog('sharedblocks', t('Block @description was successfully fetched.', array(
        '@description' => $row['description'],
      )));
    }
    else {
      watchdog('sharedblocks', t('Could not retrieve block from @url', array(
        '@url' => $row['url'],
      )), WATCHDOG_WARNING);
    }

    // Save record to the database.
    $record['id'] = $row['id'];
    $record['expiration'] = time() + $row['update_interval'];
    drupal_write_record('sharedblocks', $record, 'id');
  }
}