From 38a8c6baccd88d5e64784f9d253208a2c16ba317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Tue, 31 Dec 2024 17:44:10 +0100 Subject: [PATCH] Allow to find existing parts via the stored providerReference This should allow the database to more quickly find entries --- .../InfoProviderSystem/ExistingPartFinder.php | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Services/InfoProviderSystem/ExistingPartFinder.php b/src/Services/InfoProviderSystem/ExistingPartFinder.php index 48a7cf6d..1641f24f 100644 --- a/src/Services/InfoProviderSystem/ExistingPartFinder.php +++ b/src/Services/InfoProviderSystem/ExistingPartFinder.php @@ -41,12 +41,22 @@ final class ExistingPartFinder $qb = $this->em->getRepository(Part::class)->createQueryBuilder('part'); $qb->select('part') ->leftJoin('part.manufacturer', 'manufacturer') - //The manufacturer name must match - ->where("ILIKE(manufacturer.name, :manufacturerName) = TRUE") - //And the manufacturer product number must match - ->andWhere( - "ILIKE(part.manufacturer_product_number, :mpn) = TRUE" - ); + ->Orwhere($qb->expr()->andX( + 'part.providerReference.provider_key = :providerKey', + 'part.providerReference.provider_id = :providerId', + )) + + //Or the manufacturer and the MPN must match + ->OrWhere( + $qb->expr()->andX( + "ILIKE(manufacturer.name, :manufacturerName) = TRUE", + "ILIKE(part.manufacturer_product_number, :mpn) = TRUE" + ) + ) + ; + + $qb->setParameter('providerKey', $dto->provider_key); + $qb->setParameter('providerId', $dto->provider_id); $qb->setParameter('manufacturerName', $dto->manufacturer); $qb->setParameter('mpn', $dto->mpn);