diff --git a/Entity/EmailRepository.php b/Entity/EmailRepository.php index 6d2d494..6be2aa9 100644 --- a/Entity/EmailRepository.php +++ b/Entity/EmailRepository.php @@ -18,8 +18,20 @@ public function addEmail(Email $email) $email->setStatus(Email::STATUS_READY); $email->setRetries(0); $email->setCreatedAt(new \DateTime()); + + $scheduledDbChanges = 0; + $scheduledDbChanges += count($em->getUnitOfWork()->getScheduledEntityInsertions()); + $scheduledDbChanges += count($em->getUnitOfWork()->getScheduledEntityUpdates()); + $scheduledDbChanges += count($em->getUnitOfWork()->getScheduledEntityDeletions()); + $scheduledDbChanges += count($em->getUnitOfWork()->getScheduledCollectionUpdates()); + $scheduledDbChanges += count($em->getUnitOfWork()->getScheduledCollectionUpdates()); + $em->persist($email); - $em->flush(); + + // Flush only if there are not other db changes + if ($scheduledDbChanges === 0) { + $em->flush(); + } } public function getAllEmails($limit = null, $offset = null)