diff --git a/lib/API/JSON/v1/SendingQueue.php b/lib/API/JSON/v1/SendingQueue.php index 5c53f74956..f8976dbc03 100644 --- a/lib/API/JSON/v1/SendingQueue.php +++ b/lib/API/JSON/v1/SendingQueue.php @@ -187,7 +187,7 @@ class SendingQueue extends APIEndpoint { $newsletter = $this->newsletterRepository->findOneById($newsletterId); if ($newsletter instanceof NewsletterEntity) { - $queue = $newsletter->getLatestQueue(); + $queue = $newsletter->getLastUpdatedQueue(); if (!$queue instanceof SendingQueueEntity) { return $this->errorResponse([ @@ -217,7 +217,7 @@ class SendingQueue extends APIEndpoint { $newsletter = $this->newsletterRepository->findOneById($newsletterId); if ($newsletter instanceof NewsletterEntity) { - $queue = $newsletter->getLatestQueue(); + $queue = $newsletter->getLastUpdatedQueue(); if (!$queue instanceof SendingQueueEntity) { return $this->errorResponse([ diff --git a/lib/Entities/NewsletterEntity.php b/lib/Entities/NewsletterEntity.php index cc99df6988..ebccfe88d2 100644 --- a/lib/Entities/NewsletterEntity.php +++ b/lib/Entities/NewsletterEntity.php @@ -454,16 +454,20 @@ class NewsletterEntity { return $this->queues; } - /** - * @return SendingQueueEntity|null - */ - public function getLatestQueue() { + public function getLatestQueue(): ?SendingQueueEntity { $criteria = new Criteria(); $criteria->orderBy(['id' => Criteria::DESC]); $criteria->setMaxResults(1); return $this->queues->matching($criteria)->first() ?: null; } + public function getLastUpdatedQueue(): ?SendingQueueEntity { + $criteria = new Criteria(); + $criteria->orderBy(['updatedAt' => Criteria::DESC]); + $criteria->setMaxResults(1); + return $this->queues->matching($criteria)->first() ?: null; + } + /** * @return Collection */