Example #1
0
 /**
  * Runs the import
  */
 public function run(Feed $feed)
 {
     $this->startTime = microtime(true);
     while ($item = $this->getNextItem($feed)) {
         // increase item count
         $this->processed++;
         // dispatch event for next item
         $event = new ItemEvent($this, $item);
         $this->eventDispatcher->dispatch(ImportEvents::ITEM_START, $event);
         // import the item
         try {
             $source = $this->handler->handle($this->import->getFeed(), $item);
             $this->successItem($item, $source);
         } catch (FailedItemException $e) {
             $this->failItem($item, $e->getMessage());
         }
         // item done
         $this->eventDispatcher->dispatch(ImportEvents::ITEM_FINISH, $event);
         // clear entitymanager after batch
         if ($this->processed % $this->batchSize === 0) {
             $this->flush();
             $this->clear();
         }
     }
     // flush remaining changes
     $this->flush();
     $this->clear();
     $this->logger->finishImportLog($this->import);
     $this->logger->logImportResult($this);
 }
Example #2
0
 /**
  * Removes the log for an import
  *
  * @param Import $import
  */
 public function removeImportLog(Import $import)
 {
     $this->logger->debug(sprintf('Removing log for import <info>%d</info>', $import->getId()));
     $this->itemLogger->delete($this->getImportItemSetName($import));
 }
Example #3
0
 /**
  * @param Import                   $import
  * @param EventDispatcherInterface $dispatcher
  * @param array                    $options
  *
  * @return Importer
  */
 protected function createImporter(Import $import, EventDispatcherInterface $dispatcher, array $options = [])
 {
     $builder = $this->importerBuilderFactory->create($dispatcher);
     $type = $this->registry->getImporterType($import->getFeed()->getImporterType());
     $options = array_merge($options, $import->getFeed()->getImporterOptions());
     return $builder->build($type, $import, $this->getImportHandler($import), $this->logger, $options);
 }