From 4bffdc46a310c9dd3cd256c03c454bdb41fd5fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Sun, 25 Jan 2026 18:27:14 +0100 Subject: [PATCH] fix: update database queries for mysql 8 compatibility --- src/Repository/AssignmentRepository.php | 16 ++++++++++++---- src/Repository/DestinationRepository.php | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Repository/AssignmentRepository.php b/src/Repository/AssignmentRepository.php index 105f851..e0fbf36 100644 --- a/src/Repository/AssignmentRepository.php +++ b/src/Repository/AssignmentRepository.php @@ -5,6 +5,7 @@ namespace App\Repository; use App\Entity\Application; use App\Entity\Assignment; use App\Entity\Teamer; +use App\Entity\Training; use App\Model\AssignmentFilterDto; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\ORM\Query; @@ -66,7 +67,6 @@ class AssignmentRepository extends ServiceEntityRepository ->select('assignment', 'destination', 'job_profile', 'application', 'disposition') ->innerJoin('assignment.destination', 'destination') ->innerJoin('assignment.jobProfile', 'job_profile') - ->leftJoin('job_profile.requiredTrainings', 'required_training') ->where($qb->expr()->andX( $qb->expr()->orX( $qb->expr()->gt('destination.dateFrom', ':now'), @@ -81,7 +81,6 @@ class AssignmentRepository extends ServiceEntityRepository )) ->leftJoin('assignment.applications', 'application', Join::WITH, $qb->expr()->eq('application.teamer', ':teamer')) ->leftJoin('assignment.dispositions', 'disposition', Join::WITH, $qb->expr()->eq('disposition.teamer', ':teamer')) - ->groupBy('assignment') ->setParameter('teamer', $teamer) ->setParameter('status', [Assignment::STATUS_DRAFT, Assignment::STATUS_CALLED_OFF]) ->setParameter('now', new \DateTimeImmutable()) @@ -89,8 +88,17 @@ class AssignmentRepository extends ServiceEntityRepository // limit result for teamers not having any trainings AND licences if (0 === $teamer->getTrainingAttendances()->count() && 0 === $teamer->getLicenses()->count()) { + // Use NOT EXISTS subquery instead of JOIN to avoid duplicates requiring GROUP BY + $subQb = $this->getEntityManager()->createQueryBuilder(); + $subQb + ->select('1') + ->from(Training::class, 'rt') + ->join('rt.jobProfiles', 'jp') + ->where('jp = job_profile') + ; + $qb - ->andWhere($qb->expr()->isNull('required_training')) + ->andWhere($qb->expr()->not($qb->expr()->exists($subQb->getDQL()))) ->andWhere($qb->expr()->eq('job_profile.requiredLicenses', ':requiredLicenses')) ->setParameter('requiredLicenses', '[]') ; @@ -346,7 +354,7 @@ class AssignmentRepository extends ServiceEntityRepository $codes = []; $result = $qb - ->select('assignment.id', 'destination.hotelCode') + ->select('destination.hotelCode') ->innerJoin('assignment.destination', 'destination') ->groupBy('destination.hotelCode') ->orderBy('destination.hotelCode', 'ASC') diff --git a/src/Repository/DestinationRepository.php b/src/Repository/DestinationRepository.php index 5b62dfd..045222a 100644 --- a/src/Repository/DestinationRepository.php +++ b/src/Repository/DestinationRepository.php @@ -118,7 +118,7 @@ class DestinationRepository extends ServiceEntityRepository return $qb ->select('destination.hotel', 'destination.hotelCode', 'destination.hotelBusProId') - ->groupBy('destination.hotelBusProId') + ->groupBy('destination.hotelBusProId', 'destination.hotel', 'destination.hotelCode') ->orderBy('destination.hotel', 'ASC') ->getQuery() ->getArrayResult()