Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More options for finding Objects by sourceId, prevent finding duplicates #1665

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading