public function import($row) { switch ($this->importBehaviour) { case self::IMPORTBEHAVIOUR_IGNORE: return null; break; case self::IMPORTBEHAVIOUR_CREATENEW: $this->log(sprintf("Would create a new entity of type %s for relation %s", $this->baseEntity, $this->getAssociationName())); return parent::import($row); break; } return null; }
public function import($row) { $descriptions = []; switch ($this->importBehaviour) { case self::IMPORTBEHAVIOUR_ALWAYSSETTO: $targetEntity = $this->iriConverter->getItemFromIri($this->setToEntity); $this->log(sprintf("Would set %s to %s#%s", $this->associationName, $this->baseEntity, $targetEntity->getId())); return $targetEntity; break; case self::IMPORTBEHAVIOUR_MATCHDATA: $configuration = []; foreach ($this->matchers as $matcher) { $foo = new \stdClass(); $foo->property = $matcher->matchField; $foo->operator = "="; $foo->value = $row[$matcher->importField]; $descriptions[] = sprintf("%s = %s", $matcher->matchField, $row[$matcher->importField]); $configuration[] = $foo; } $configuration = $this->advancedSearchFilter->extractConfiguration($configuration, []); $filters = $configuration['filters']; $sorters = $configuration['sorters']; $qb = new \Doctrine\ORM\QueryBuilder($this->em); $qb->select("o")->from($this->baseEntity, "o"); $this->advancedSearchFilter->filter($qb, $filters, $sorters); try { $result = $qb->getQuery()->getSingleResult(); if ($this->updateBehaviour === self::UPDATEBEHAVIOUR_UPDATEDATA) { // @todo Update the entity with the specified values } $this->log(sprintf("Would set %s to %s#%s", $this->associationName, $this->baseEntity, $result->getId())); return $result; } catch (\Exception $e) { } switch ($this->notFoundBehaviour) { case self::NOTFOUNDBEHAVIOUR_STOPIMPORT: $this->log(sprintf("Would stop import as the match %s for association %s was not found", implode(",", $descriptions), $this->getAssociationName())); break; case self::NOTFOUNDBEHAVIOUR_SETTOENTITY: $targetEntity = $this->iriConverter->getItemFromIri($this->notFoundSetToEntity); $this->log(sprintf("Would set the association %s to %s, since the match %s for association %s was not found", $this->getAssociationName(), $this->notFoundSetToEntity, implode(",", $descriptions))); return $targetEntity; break; case self::NOTFOUNDBEHAVIOUR_CREATEENTITY: $this->log(sprintf("Would create a new entity of type %s", $this->baseEntity)); return parent::import($row); break; } break; } return null; }