From 8eac95ea93549503f08fb4d1f0715c91a473d3bf Mon Sep 17 00:00:00 2001 From: Wilco Louwerse Date: Thu, 26 Sep 2024 17:54:45 +0200 Subject: [PATCH] More options for finding Objects by sourceId, prevent finding duplicates --- api/src/Repository/ObjectEntityRepository.php | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/api/src/Repository/ObjectEntityRepository.php b/api/src/Repository/ObjectEntityRepository.php index b20e36304..d048b477e 100644 --- a/api/src/Repository/ObjectEntityRepository.php +++ b/api/src/Repository/ObjectEntityRepository.php @@ -115,18 +115,29 @@ public function getOrderParameters(Entity $Entity, string $prefix = '', int $lev * Finds object entities on their id or a sourceId of a synchronization this ObjectEntity has. * * @param string $identifier - * - * @throws NonUniqueResultException + * @param string|null $gatewayId The gateway (/source) id to use when searching for Synchronizations. + * @param string|null $entityId The entity id to use when searching for Synchronizations. * * @return ObjectEntity The found object entity + * @throws NonUniqueResultException */ - public function findByAnyId(string $identifier): ?ObjectEntity + public function findByAnyId(string $identifier, ?string $gatewayId = null, ?string $entityId = null): ?ObjectEntity { $query = $this->createQueryBuilder('o') ->leftJoin('o.synchronizations', 's') ->where('s.sourceId = :identifier') ->setParameter('identifier', $identifier); + if ($gatewayId !== null) { + $query->andWhere('s.gateway = :gatewayId') + ->setParameter('gatewayId', $gatewayId); + } + + if ($entityId !== null) { + $query->andWhere('s.entity = :entityId') + ->setParameter('entityId', $entityId); + } + if (Uuid::isValid($identifier)) { $query->orWhere('o.id = :identifier'); } @@ -977,9 +988,9 @@ private function makeKeySqlFriendly(string $key): string /** * Finds all object entities with references. - * + * * @param array $references The entity references - * + * * @return mixed ObjectEntities */ public function findByReferences(array $references)