Fix canceling multiple automatic emails
When we deleted sending queue using SQL it remained in the entity manager and subsequent flush (not the first one) triggered the error, because it didn't know the ScheduledTask entity attached to the orphaned SendingQueue entity. This commit fixes this by refactoring deletion of sending queue using standard repository method. After fixing the issue for sending queue there was another issue with SchedulesTaskSubscriberEntity that remained in memory. I fixed that by detaching those. Theoretically there might be many SchedulesTaskSubscriberEntities for an Automatic email so I consider still safer to delete using SQL and if there are some loaded (in this case there is one) detach them. [MAILPOET-4741]
This commit is contained in:
committed by
Aschepikov
parent
655641737b
commit
cd3652eaa6
@@ -122,8 +122,15 @@ class AutomaticEmailScheduler {
|
||||
// try to find existing scheduled task for given subscriber
|
||||
$task = $this->scheduledTasksRepository->findOneScheduledByNewsletterAndSubscriber($newsletter, $subscriber);
|
||||
if ($task) {
|
||||
$this->sendingQueuesRepository->deleteByTask($task);
|
||||
$queue = $task->getSendingQueue();
|
||||
if ($queue instanceof SendingQueueEntity) {
|
||||
$this->sendingQueuesRepository->remove($queue);
|
||||
}
|
||||
$this->scheduledTaskSubscribersRepository->deleteByTask($task);
|
||||
// In case any of task associated SchedulesTaskSubscriberEntity was loaded we need to detach them
|
||||
foreach ($task->getSubscribers() as $taskSubscriber) {
|
||||
$this->scheduledTaskSubscribersRepository->detach($taskSubscriber);
|
||||
}
|
||||
$this->scheduledTasksRepository->remove($task);
|
||||
$this->scheduledTasksRepository->flush();
|
||||
}
|
||||
|
Reference in New Issue
Block a user