/** * @return ImportResult */ public function run() { $import = $this->part->getImport(); // part is not finished, maybe it's already started/running if ($this->part->isStarted()) { $this->processor->checkProcessing($this->part); $this->logger->warning(sprintf('Part %d of import %d has already started, but the process (%s) is no longer running. ' . 'Resuming the part now.', $this->part->getPosition(), $import->getId(), $this->part->getProcess())); } // start import if necessary if (!$import->isStarted()) { $this->importer->dispatchEvent(ImportEvents::IMPORT_START, new ImportEvent($import)); $this->repository->startImport($import); } try { $this->start(); $this->importer->run($this->feed); } catch (\Exception $e) { // log the error $this->logger->error($e->getMessage()); $this->logger->debug($e->getTraceAsString()); // check if we have any retries left if ($this->part->getRetries() > 0) { // mark as unstarted and bail out $this->retry(); return null; } else { $this->fail($e->getMessage()); } } $this->repository->addResult($import, $this->importer->getResult()); $this->finish(); return $this->importer->getResult(); }
/** * @param ImportPart $part */ public function finishImportPart(ImportPart $part) { if (!$part->isStarted()) { throw new \RuntimeException('Import part has not yet started'); } $part->setDatetimeEnded(new \DateTime()); $this->savePart($part); }