You are here

function amazon_cron in Amazon Product Advertisement API 6

Same name and namespace in other branches
  1. 7.2 amazon.module \amazon_cron()
  2. 7 amazon.module \amazon_cron()

File

./amazon.module, line 791

Code

function amazon_cron() {

  // Here, we're going to chug through all the existing ASINs and update them.
  // We'll grab 50 at a time to avoid thrashing things.
  $sql = "SELECT asin FROM {amazon_item} WHERE timestamp < %d";
  $result = db_query_range($sql, time() - variable_get('amazon_refresh_schedule', 86400), 0, 50);
  $asins = array();
  while ($item = db_fetch_array($result)) {
    $asins[] = $item['asin'];
  }
  if (!empty($asins)) {
    if ($items = amazon_item_lookup_from_web($asins)) {
      foreach ($items as $item) {
        amazon_item_insert($item);
      }
      watchdog('amazon', 'Amazon items were updated.');
    }
    else {
      watchdog('amazon', 'Amazon items could not be updated.');
    }
  }
}