You are here

public function FeedsSource::pushImport in Feeds 7.2

Imports a fetcher result all at once in memory.

Parameters

FeedsFetcherResult $fetcher_result: The fetcher result to process.

Throws

Exception Thrown if an error occurs when importing.

File

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

Class

FeedsSource
Holds the source of a feed to import.

Code

public function pushImport(FeedsFetcherResult $fetcher_result) {

  // Since locks only work during a request, check if an import is active.
  if (!empty($this->fetcher_result) || !empty($this->state)) {
    throw new RuntimeException('The feed is currently importing.');
  }
  $this
    ->acquireLock();
  $this->state[FEEDS_START] = time();
  try {
    module_invoke_all('feeds_before_import', $this);

    // Parse.
    do {
      $parser_result = $this->importer->parser
        ->parse($this, $fetcher_result);
      module_invoke_all('feeds_after_parse', $this, $parser_result);

      // Process.
      $this->importer->processor
        ->process($this, $parser_result);
    } while ($this
      ->progressParsing() !== FEEDS_BATCH_COMPLETE);
  } catch (Exception $e) {

    // $e is stored and re-thrown once we've had a chance to log our progress.
    // Set the exception so that other modules can check if an exception
    // occurred in hook_feeds_after_import().
    $this->exception = $e;
  }
  $this
    ->finishImport();
  $this
    ->save();
  $this
    ->releaseLock();
  if (isset($e)) {
    throw $e;
  }
}