Skip to content

Commit

Permalink
refactor: improve getCurrentRevision repo function
Browse files Browse the repository at this point in the history
  • Loading branch information
Davidmattei committed Jul 12, 2024
1 parent d45ee33 commit bf6511d
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions EMS/core-bundle/src/Repository/RevisionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bf6511d

Please sign in to comment.