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)