You are here

function feeds_crawler_batch in Feeds Crawler 6

Same name and namespace in other branches
  1. 6.2 feeds_crawler.module \feeds_crawler_batch()

Batch callback.

1 string reference to 'feeds_crawler_batch'
feeds_crawler_admin_form_submit in ./feeds_crawler.admin.inc

File

./feeds_crawler.module, line 23

Code

function feeds_crawler_batch($importer_id, $nid, $xpath, $offset_url, $num_pages, $autodetect, $html, &$context) {
  require_once 'FeedsSourceCrawler.inc';
  $feeds_source_class = variable_get('feeds_source_class', NULL);
  variable_set('feeds_source_class', 'FeedsSourceCrawler');
  $source = feeds_source($importer_id, $nid);
  if (!isset($context['sandbox']['progress'])) {
    $context['sandbox']['progress'] = 0;
  }
  if (!$offset_url) {
    $offset_url = $source->config['FeedsHTTPFetcher']['source'];
  }
  if (!isset($context['sandbox']['next_url'])) {
    $context['sandbox']['next_url'] = $offset_url;
  }
  $base_url = feeds_crawler_base($source->config['FeedsHTTPFetcher']['source']);
  $source
    ->setHTTPSource($context['sandbox']['next_url']);
  while (FEEDS_BATCH_COMPLETE != $source
    ->import()) {
  }
  $next_url = feeds_crawler_find_next($autodetect, $xpath, $source
    ->getRaw(), $base_url, $html);
  if ($next_url === FALSE) {
    feeds_crawler_reset_source_class($feeds_source_class);
    $context['finished'] = 1;
    if ($num_pages != 0) {
      drupal_set_message(t('Unable to find the next link.'), 'error');
    }
    return;
  }
  $context['sandbox']['next_url'] = $next_url;
  $context['sandbox']['progress']++;
  if ($num_pages != 0) {
    $context['finished'] = $context['sandbox']['progress'] / $num_pages;
  }
  else {
    $context['finished'] = $context['sandbox']['progress'] / 1000000;
  }
  feeds_crawler_reset_source_class($feeds_source_class);
}