fix: use correct database query to find overlapping applications

addresses #869aug4uz
This commit is contained in:
Björn Fromme
2025-10-21 10:01:28 +02:00
parent f4b0dda38b
commit 06203f86ec
2 changed files with 27 additions and 4 deletions
@@ -38,6 +38,7 @@ class InvalidateApplicationsListener
// - Complete containment in either direction // - Complete containment in either direction
// - Exact date matches // - Exact date matches
// Note: Periods that only touch at boundaries (e.g., Jan 1-7 and Jan 7-12) are NOT considered overlapping // 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 $qb = $this
->entityManager ->entityManager
->getRepository(Application::class) ->getRepository(Application::class)
@@ -46,10 +47,29 @@ class InvalidateApplicationsListener
/** @var array<Application> $applications */ /** @var array<Application> $applications */
$applications = $qb $applications = $qb
->innerJoin('application.assignment', 'assignment') ->innerJoin('application.assignment', 'assignment')
->innerJoin('assignment.destination', 'destination')
->where($qb->expr()->andX( ->where($qb->expr()->andX(
$qb->expr()->eq('application.teamer', ':teamer'), $qb->expr()->eq('application.teamer', ':teamer'),
$qb->expr()->lt('assignment.dateFrom', ':dateTo'), $qb->expr()->orX(
$qb->expr()->gt('assignment.dateTo', ':dateFrom'), $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') $qb->expr()->neq('application.status', ':status')
)) ))
->setParameter('teamer', $teamer) ->setParameter('teamer', $teamer)
@@ -306,10 +306,13 @@ class InvalidateApplicationsListenerTest extends TestCase
$expr = $this->createMock(Expr::class); $expr = $this->createMock(Expr::class);
$expr->method('andX')->willReturnSelf(); $expr->method('andX')->willReturnSelf();
$expr->method('orX')->willReturnSelf();
$expr->method('eq')->willReturnSelf(); $expr->method('eq')->willReturnSelf();
$expr->method('lte')->willReturnSelf(); $expr->method('lt')->willReturnSelf();
$expr->method('gte')->willReturnSelf(); $expr->method('gt')->willReturnSelf();
$expr->method('neq')->willReturnSelf(); $expr->method('neq')->willReturnSelf();
$expr->method('isNull')->willReturnSelf();
$expr->method('isNotNull')->willReturnSelf();
$queryBuilder = $this->createMock(QueryBuilder::class); $queryBuilder = $this->createMock(QueryBuilder::class);
$queryBuilder->method('expr')->willReturn($expr); $queryBuilder->method('expr')->willReturn($expr);