You are here

public function FeedImportProcessor::process in Feed Import 7.3

Processes the import.

File

feed_import_base/inc/feed_import.inc, line 1680
This file contains Feed Import helpers.

Class

FeedImportProcessor
Class that processess the import.

Code

public function process() {

  // Give import time (for large imports).
  // Well, if safe mode is on this cannot be done so it may break import.
  if (!ini_get('safe_mode')) {
    set_time_limit(0);
  }

  // Reset report.
  $this->report['started'] = time();
  $entities = array();
  $reader = $this->reader;
  if ($this->itemsCount) {
    $current = 0;

    // Get next item from reader.
    while ($item = $reader
      ->get()) {

      // Create the entity.
      $entities[] =& $this
        ->createEntity($item);

      // Check for save.
      if (++$current == $this->itemsCount) {
        unset($item);
        $this
          ->saveEntities($entities);
        $current = 0;
        $entities = array();
      }
    }
  }
  else {

    // Get next item from reader.
    while ($item = $reader
      ->get()) {

      // Create entity.
      $entities[] =& $this
        ->createEntity($item);
    }
  }

  // Check for left over entities.
  if ($entities) {
    $this
      ->saveEntities($entities);
  }

  // Not needed anymore.
  unset($entities, $reader);

  // Reset the static cache.
  if ($this->staticCacheEntities && $this->resetStaticCache) {
    $this->entityInfo->controller->canResetCache && $this->entityInfo->controller
      ->resetCache();
    $this->staticCacheEntities = 0;
  }

  // Commit left over hash updates.
  $this->hashes
    ->updateCommit();

  // Also the new hash inserts.
  $this->hashes
    ->insertCommit();

  // Remove orphan hashes.
  if ($this->orphanHashes) {
    $this->hashes
      ->delete($this->orphanHashes);
    $this->orphanHashes = array();
  }
  $this->report['finished'] = time();
  $report = $this->report;

  // Reset report
  $this->report = array(
    'total' => 0,
    'updated' => 0,
    'new' => 0,
    'rescheduled' => 0,
    'skipped' => 0,
    'protected' => 0,
    'protected_skipped' => 0,
    'missing' => 0,
    'started' => 0,
    'finished' => 0,
    'errors' => array(),
  );
  return $report;
}