You are here

public function FeedsSource::import in Feeds 6

Same name and namespace in other branches
  1. 7.2 includes/FeedsSource.inc \FeedsSource::import()
  2. 7 includes/FeedsSource.inc \FeedsSource::import()

Import a feed: execute fetching, parsing and processing stage.

Return value

FEEDS_BATCH_COMPLETE if the import process finished. A decimal between 0.0 and 0.9 periodic if import is still in progress.

Throws

Throws Exception if an error occurs when importing.

File

includes/FeedsSource.inc, line 140
Definition of FeedsSourceInterface and FeedsSource class.

Class

FeedsSource
This class encapsulates a source of a feed. It stores where the feed can be found and how to import it.

Code

public function import() {
  try {
    if (!$this->batch || !$this->batch instanceof FeedsImportBatch) {
      $this->batch = $this->importer->fetcher
        ->fetch($this);
      $this->importer->parser
        ->parse($this->batch, $this);
      module_invoke_all('feeds_after_parse', $this->importer, $this);
    }
    $this->importer->processor
      ->process($this->batch, $this);
    $result = $this->batch
      ->getProgress();
    if ($result == FEEDS_BATCH_COMPLETE) {
      unset($this->batch);
      module_invoke_all('feeds_after_import', $this->importer, $this);
    }
  } catch (Exception $e) {
    unset($this->batch);
    $this
      ->save();
    throw $e;
  }
  $this
    ->save();
  return $result;
}