You are here

public function FeedsSource::import in Feeds 7.2

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

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

This method only executes the current batch chunk, then returns. If you are looking to import an entire source, use FeedsSource::startImport() instead.

Return value

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

Throws

Exception In case an error occurs when importing.

File

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

Class

FeedsSource
Holds the source of a feed to import.

Code

public function import() {
  $this
    ->acquireLock();
  try {

    // If fetcher result is empty, we are starting a new import, log.
    if (empty($this->fetcher_result)) {
      module_invoke_all('feeds_before_import', $this);
      if (module_exists('rules')) {
        rules_invoke_event('feeds_before_import', $this);
      }
      $this->state[FEEDS_START] = time();
    }

    // Fetch.
    if (empty($this->fetcher_result) || FEEDS_BATCH_COMPLETE == $this
      ->progressParsing()) {
      $this->fetcher_result = $this->importer->fetcher
        ->fetch($this);

      // Clean the parser's state, we are parsing an entirely new file.
      unset($this->state[FEEDS_PARSE]);
    }

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

    // Process.
    $this->importer->processor
      ->process($this, $parser_result);

    // Import finished without exceptions, so unset any potentially previously
    // recorded exceptions.
    unset($this->exception);
  } 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;
  }

  // Clean up.
  $result = $this
    ->progressImporting();
  if ($result == FEEDS_BATCH_COMPLETE || isset($e)) {
    $this
      ->finishImport();
  }
  $this
    ->save();
  $this
    ->releaseLock();
  if (isset($e)) {
    throw $e;
  }
  return $result;
}