You are here

public function FeedsCrawlerBase::fetch in Feeds Crawler 7.2

File

src/FeedsCrawlerBase.php, line 32
Contains FeedsCrawler.

Class

FeedsCrawlerBase
The fetcher class that implements crawling.

Code

public function fetch(FeedsSource $source) {
  $source_config = $source
    ->getConfigFor($this);

  // If this is only configured to execute on the first run.
  if ($this->config['first_run'] && $source_config['crawled']) {
    return $this
      ->getFetcherResult($source_config['source']);
  }
  $state = $source
    ->state(FEEDS_FETCH);
  $this
    ->beginFetch($source, $state);
  $url = isset($state->next_url) ? $state->next_url : $source_config['source'];
  try {
    $state->next_url = $this
      ->getNextUrl($source, $url);
    $this
      ->endFetch($source, $state);
  } catch (FeedsCrawlerLinkNotFoundException $e) {
    $state
      ->progress(1, 1);
  }
  if ($state->progress == FEEDS_BATCH_COMPLETE) {
    $source_config['crawled'] = TRUE;
    $source
      ->setConfigFor($this, $source_config);
  }
  return $this
    ->getFetcherResult($url);
}