Exemple #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;
 }
Exemple #2
0
 /**
  * @param \HDNET\Importr\Domain\Model\Import $import
  * @param int|null                           $pointer
  */
 public function updateImport(Import $import, $pointer = null)
 {
     if (is_int($pointer)) {
         $import->setPointer($pointer);
     }
     $this->importRepository->update($import);
     $this->persistenceManager->persistAll();
 }
Exemple #3
0
 /**
  * @test
  */
 public function do_all_increases_work_correctly()
 {
     $types = [TargetInterface::RESULT_INSERT => 'getInserted', TargetInterface::RESULT_UPDATE => 'getUpdated', TargetInterface::RESULT_IGNORED => 'getIgnored', TargetInterface::RESULT_UNSURE => 'getUnknowns', TargetInterface::RESULT_ERROR => 'getErrors'];
     foreach ($types as $type => $getter) {
         $import = new Import();
         $import->increaseCount($type);
         $this->assertEquals(1, $import->{$getter}());
     }
 }
Exemple #4
0
 /**
  * To rename a file from the importr you
  * have to use the "rename: 1" statement in
  * your configuration. The file will be
  * prefixed with the current (human readable)
  * timestamp.
  *
  * Caution: after this method, the file is moved
  * you should only use this in the before
  * configuration if you are fully aware of it!
  *
  * @param  ManagerInterface $manager
  * @param  Import           $import
  * @return void
  */
 public function execute(ManagerInterface $manager, Import $import)
 {
     $configuration = $import->getStrategy()->getConfiguration();
     if (isset($configuration['after']['rename'])) {
         $oldFileName = $this->fileService->getFileAbsFileName($import->getFilepath());
         $info = pathinfo($oldFileName);
         $newFileName = $info['dirname'] . DIRECTORY_SEPARATOR . date('YmdHis') . '_' . $info['basename'];
         rename($oldFileName, $newFileName);
     }
 }
Exemple #5
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;
     }
 }
Exemple #6
0
 /**
  * @param \HDNET\Importr\Domain\Model\Import $import
  *
  * @return array
  */
 protected function initializeTargets(Import $import)
 {
     $targets = [];
     $targetConfiguration = $import->getStrategy()->getTargets();
     foreach ($targetConfiguration as $target => $configuration) {
         $object = $this->objectManager->get($target);
         $object->setConfiguration($configuration);
         $object->getConfiguration();
         $object->start($import->getStrategy());
         $targets[$target] = $object;
     }
     return $targets;
 }