Use the latest updated queue

[MAILPOET-3876]
This commit is contained in:
Pavel Dohnal
2021-11-09 10:52:23 +01:00
committed by Veljko V
parent 09719ca450
commit 5890fb3510
2 changed files with 10 additions and 6 deletions

View File

@ -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([

View File

@ -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<int, SendingQueueEntity>
*/