Fix error after refactor of SendingErrorHandler

In 862c395d3263f30057aef73a14704345e181dde3, SendingErrorHandler was
refactored to replace the `\MailPoet\Tasks\Sending` class with Doctrine
code. Inside `processSoftError()`, a call to
`$sendingTask->saveSubscriberError()` was replaced with a call to
`$this->scheduledTaskSubscribersRepository->saveError()`. The problem is
that the former updates the processed and unprocessed counts in the
QueueEntity while the later doesn't.

This commit fixes this issue by calling
`$this->sendingQueuesRepository->updateCounts()` inside
`processSoftError()`.

[MAILPOET-5682]
This commit is contained in:
Rodrigo Primo
2023-11-21 15:45:52 -03:00
committed by Jan Jakeš
parent 7bb40664cc
commit e7416c247c

View File

@ -3,9 +3,11 @@
namespace MailPoet\Cron\Workers\SendingQueue;
use MailPoet\Entities\ScheduledTaskEntity;
use MailPoet\Entities\SendingQueueEntity;
use MailPoet\Mailer\MailerError;
use MailPoet\Mailer\MailerLog;
use MailPoet\Newsletter\Sending\ScheduledTaskSubscribersRepository;
use MailPoet\Newsletter\Sending\SendingQueuesRepository;
class SendingErrorHandler {
/** @var ScheduledTaskSubscribersRepository */
@ -14,12 +16,17 @@ class SendingErrorHandler {
/** @var SendingThrottlingHandler */
private $throttlingHandler;
/** @var SendingQueuesRepository */
private $sendingQueuesRepository;
public function __construct(
ScheduledTaskSubscribersRepository $scheduledTaskSubscribersRepository,
SendingThrottlingHandler $throttlingHandler
SendingThrottlingHandler $throttlingHandler,
SendingQueuesRepository $sendingQueuesRepository
) {
$this->scheduledTaskSubscribersRepository = $scheduledTaskSubscribersRepository;
$this->throttlingHandler = $throttlingHandler;
$this->sendingQueuesRepository = $sendingQueuesRepository;
}
public function processError(
@ -52,5 +59,11 @@ class SendingErrorHandler {
$message = $subscriberError->getMessage() ?: $error->getMessage();
$this->scheduledTaskSubscribersRepository->saveError($task, $preparedSubscribersIds[$subscriberIdIndex], $message ?? '');
}
$queue = $task->getSendingQueue();
if ($queue instanceof SendingQueueEntity) {
$this->sendingQueuesRepository->updateCounts($queue);
}
}
}