From bf6511de4463ebe5c691110e1a1613aa0ea1f09b Mon Sep 17 00:00:00 2001 From: David mattei Date: Fri, 12 Jul 2024 14:36:01 +0200 Subject: [PATCH] refactor: improve getCurrentRevision repo function --- .../src/Repository/RevisionRepository.php | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/EMS/core-bundle/src/Repository/RevisionRepository.php b/EMS/core-bundle/src/Repository/RevisionRepository.php index 7a8179b33..c2338d6e9 100644 --- a/EMS/core-bundle/src/Repository/RevisionRepository.php +++ b/EMS/core-bundle/src/Repository/RevisionRepository.php @@ -478,20 +478,19 @@ public function finaliseRevision(ContentType $contentType, string $ouuid, \DateT public function getCurrentRevision(ContentType $contentType, string $ouuid): ?Revision { - $qb = $this->createQueryBuilder('r')->select() - ->where('r.contentType = ?2') - ->andWhere('r.ouuid = ?3') - ->andWhere('r.endTime is null') - ->setParameter(2, $contentType) - ->setParameter(3, $ouuid); + $qb = $this->createQueryBuilder('r'); + $qb + ->andWhere($qb->expr()->eq('r.ouuid', ':ouuid')) + ->andWhere($qb->expr()->eq('r.contentType', ':contentType')) + ->andWhere($qb->expr()->isNull('r.endTime')) + ->setParameters([ + 'ouuid' => $ouuid, + 'contentType' => $contentType, + ]); - /** @var Revision[] $currentRevision */ - $currentRevision = $qb->getQuery()->execute(); - if (isset($currentRevision[0])) { - return $currentRevision[0]; - } else { - return null; - } + $revision = $qb->getQuery()->getSingleResult(); + + return $revision instanceof Revision ? $revision : null; } public function publishRevision(Revision $revision, bool $draft = false): int