Пример #1
0
 /**
  * @param Import $import
  * @param array $targets
  * @param array $configuration
  * @param ResourceInterface $resource
  * @param ManagerInterface $manager
  * @return bool
  * @throws \HDNET\Importr\Exception\ReinitializeException
  */
 public function process(Import $import, array $targets, array $configuration, ResourceInterface $resource, ManagerInterface $manager)
 {
     // Resourcen Object anhand der Datei auswählen
     if (!preg_match($resource->getFilepathExpression(), $import->getFilepath())) {
         return false;
     }
     $this->configuration->process($configuration, $manager, 'before');
     // Resource "benutzen"
     $resource->parseResource();
     // Basis Import Aktualsieren (DB)
     $import->setAmount($resource->getAmount());
     $import->setStarttime(new \DateTime('now'));
     $this->importService->updateImport($import);
     // Durchlauf starten
     for ($pointer = $import->getPointer(); $pointer < $import->getAmount(); $pointer++) {
         $this->configuration->process($configuration, $manager, 'each');
         $this->processOneLine($resource, $pointer, $targets, $import);
         if (($pointer + 1) % $manager->getUpdateInterval() == 0) {
             $this->importService->updateImport($import, $pointer + 1);
         }
     }
     $import->setEndtime(new \DateTime('now'));
     $this->importService->updateImport($import, $pointer);
     $this->configuration->process($configuration, $manager, 'after');
     return true;
 }
Пример #2
0
 /**
  * @param TargetInterface $target
  * @param mixed $entry
  * @param Import $import
  * @param int $pointer
  *
  * @throws \Exception
  */
 public function process(TargetInterface $target, $entry, Import $import, $pointer)
 {
     try {
         $entry = $this->emitEntrySignal('preProcess', $target->getConfiguration(), $entry);
         $result = $target->processEntry($entry);
         $import->increaseCount($result);
     } catch (\Exception $e) {
         $import->increaseCount(TargetInterface::RESULT_ERROR);
         $this->importService->updateImport($import, $pointer + 1);
         throw $e;
     }
 }
Пример #3
0
 /**
  * @test
  */
 public function updates_current_import_status()
 {
     $import = $this->getMock(Import::class);
     $import->expects($this->once())->method('getFilepath')->will($this->returnValue('./import.csv'));
     $import->expects($this->once())->method('getPointer')->will($this->returnValue(1));
     $import->expects($this->exactly(2))->method('getAmount')->will($this->returnValue(2));
     $this->service->expects($this->exactly(3))->method('updateImport')->withConsecutive([$import], [$import, 2], [$import, 2]);
     $resource = $this->getMock(ResourceInterface::class);
     $resource->expects($this->once())->method('getFilepathExpression')->will($this->returnValue('/\\.csv$/'));
     $manager = $this->getMock(ManagerInterface::class);
     $manager->expects($this->any())->method('getUpdateInterval')->will($this->returnValue(2));
     $target = $this->getMock(TargetInterface::class);
     $result = $this->fixture->process($import, [$target], [], $resource, $manager);
 }
Пример #4
0
 /**
  *
  * @param string                               $filepath
  * @param \HDNET\Importr\Domain\Model\Strategy $strategy
  *
  * @return void
  */
 public function createAction($filepath, Strategy $strategy)
 {
     $this->importService->addToQueue($filepath, $strategy);
     $text = 'The Import file %s width the strategy %s was successfully added to the queue';
     $message = GeneralUtility::makeInstance(FlashMessage::class, sprintf($text, $filepath, $strategy->getTitle()), 'Import is in Queue', FlashMessage::INFO, true);
     $flashMessageService = $this->objectManager->get(FlashMessageService::class);
     $messageQueue = $flashMessageService->getMessageQueueByIdentifier();
     $messageQueue->addMessage($message);
     $this->redirect('index');
 }
Пример #5
0
 /**
  * @param array $configuration
  * @return $this
  */
 protected function createImport(array $configuration)
 {
     if (!isset($configuration['createImport']) && !is_array($configuration['createImport'])) {
         return $this;
     }
     foreach ($configuration['createImport'] as $create) {
         $strategy = $this->strategyRepository->findByUid((int) $create['importId']);
         if ($strategy instanceof Strategy) {
             $filepath = isset($create['filepath']) ? $create['filepath'] : '';
             $this->importService->addToQueue($filepath, $strategy, $create);
         }
     }
     return $this;
 }