You are here

function amazon_cron in Amazon Product Advertisement API 7

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

File

./amazon.module, line 833

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.
  $per_cron_limit = 50;
  $needs_update_time = REQUEST_TIME - variable_get('amazon_refresh_schedule', 86400);
  $result = db_select('amazon_item', NULL, array(
    'fetch' => PDO::FETCH_ASSOC,
  ))
    ->fields('amazon_item', array(
    'asin',
  ))
    ->condition('timestamp', $needs_update_time, '<')
    ->range(0, $per_cron_limit)
    ->execute();
  $asins = $result
    ->FetchCol();
  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.');
    }
  }
}