From 06203f86ecc3a09eec0feff9ebed4a61275d8e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Tue, 21 Oct 2025 10:01:28 +0200 Subject: [PATCH] fix: use correct database query to find overlapping applications addresses #869aug4uz --- .../InvalidateApplicationsListener.php | 24 +++++++++++++++++-- .../InvalidateApplicationsListenerTest.php | 7 ++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/EventListener/InvalidateApplicationsListener.php b/src/EventListener/InvalidateApplicationsListener.php index b7aac3d..a317191 100644 --- a/src/EventListener/InvalidateApplicationsListener.php +++ b/src/EventListener/InvalidateApplicationsListener.php @@ -38,6 +38,7 @@ class InvalidateApplicationsListener // - Complete containment in either direction // - Exact date matches // Note: Periods that only touch at boundaries (e.g., Jan 1-7 and Jan 7-12) are NOT considered overlapping + // The effective dates are determined by checking assignment dates first, falling back to destination dates if null $qb = $this ->entityManager ->getRepository(Application::class) @@ -46,10 +47,29 @@ class InvalidateApplicationsListener /** @var array $applications */ $applications = $qb ->innerJoin('application.assignment', 'assignment') + ->innerJoin('assignment.destination', 'destination') ->where($qb->expr()->andX( $qb->expr()->eq('application.teamer', ':teamer'), - $qb->expr()->lt('assignment.dateFrom', ':dateTo'), - $qb->expr()->gt('assignment.dateTo', ':dateFrom'), + $qb->expr()->orX( + $qb->expr()->andX( + $qb->expr()->isNull('assignment.dateFrom'), + $qb->expr()->lt('destination.dateFrom', ':dateTo') + ), + $qb->expr()->andX( + $qb->expr()->isNotNull('assignment.dateFrom'), + $qb->expr()->lt('assignment.dateFrom', ':dateTo') + ) + ), + $qb->expr()->orX( + $qb->expr()->andX( + $qb->expr()->isNull('assignment.dateTo'), + $qb->expr()->gt('destination.dateTo', ':dateFrom') + ), + $qb->expr()->andX( + $qb->expr()->isNotNull('assignment.dateTo'), + $qb->expr()->gt('assignment.dateTo', ':dateFrom') + ) + ), $qb->expr()->neq('application.status', ':status') )) ->setParameter('teamer', $teamer) diff --git a/tests/EventListener/InvalidateApplicationsListenerTest.php b/tests/EventListener/InvalidateApplicationsListenerTest.php index 80941e4..55a354e 100644 --- a/tests/EventListener/InvalidateApplicationsListenerTest.php +++ b/tests/EventListener/InvalidateApplicationsListenerTest.php @@ -306,10 +306,13 @@ class InvalidateApplicationsListenerTest extends TestCase $expr = $this->createMock(Expr::class); $expr->method('andX')->willReturnSelf(); + $expr->method('orX')->willReturnSelf(); $expr->method('eq')->willReturnSelf(); - $expr->method('lte')->willReturnSelf(); - $expr->method('gte')->willReturnSelf(); + $expr->method('lt')->willReturnSelf(); + $expr->method('gt')->willReturnSelf(); $expr->method('neq')->willReturnSelf(); + $expr->method('isNull')->willReturnSelf(); + $expr->method('isNotNull')->willReturnSelf(); $queryBuilder = $this->createMock(QueryBuilder::class); $queryBuilder->method('expr')->willReturn($expr);