You are here

public function FeedsSource::import in Feeds 8.2

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

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

lib/Drupal/feeds/FeedsSource.php, line 245
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.

Namespace

Drupal\feeds

Code

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

    // If fetcher result is empty, we are starting a new import, log.
    if (empty($this->fetcher_result)) {
      $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);
  } catch (Exception $e) {

    // Do nothing.
  }
  $this
    ->releaseLock();

  // Clean up.
  $result = $this
    ->progressImporting();
  if ($result == FEEDS_BATCH_COMPLETE || isset($e)) {
    $this->imported = time();
    $this
      ->log('import', 'Imported in !s s', array(
      '!s' => $this->imported - $this->state[FEEDS_START],
    ), WATCHDOG_INFO);
    module_invoke_all('feeds_after_import', $this);
    unset($this->fetcher_result, $this->state);
  }
  $this
    ->save();
  if (isset($e)) {
    throw $e;
  }
  return $result;
}