Skip to content

Commit

Permalink
Merge pull request #1665 from ConductionNL/feature/AXCVDWOF-14/tilbur…
Browse files Browse the repository at this point in the history
…g-cases-sync

More options for finding Objects by sourceId, prevent finding duplicates
  • Loading branch information
WilcoLouwerse authored Sep 27, 2024
2 parents 3057aea + 8eac95e commit 9dbbbeb
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions api/src/Repository/ObjectEntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9dbbbeb

Please sign in to comment.