Closed ghost closed 9 years ago
Thanks - could you possibly submit a PR? :-)
I would love to but I can't find any instructions on how to submit a pull request to a project I don't own so here is the patch code that stupid github won't let me upload.
From b8d8f8d9e5ee9bc9310f41e646f10a724f453a81 Mon Sep 17 00:00:00 2001
From: bjcullinan code@bjcullinan.com
Date: Wed, 3 Dec 2014 19:56:03 -0700
Subject: [PATCH] Use doctrine service to load entity manager so new entity
manager can be reset and used to email DB errors. Remove try catch because
message is minimally helpful and Symfony error handling is already very
helpful. Alternatively send emails directly with a new transport using:
/* @var \Swift_TransportEsmtpTransport $transport / $transport =
\SwiftSmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
->setUsername('username') ->setPassword('password'); /
@var \Swift_Mailer $mailer */ $mailer =
\Swift_Mailer::newInstance($transport); $mailer->send($message);
Resources/config/services.xml | 2 +- Spool/DatabaseSpool.php | 41 +++++++++++++++++++++-------------------- 2 files changed, 22 insertions(+), 21 deletions(-)
diff --git a/Resources/config/services.xml b/Resources/config/services.xml index da2f587..034a06d 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -9,7 +9,7 @@
<services>
<service id="white_october.swiftmailer_db.spool" class="%white_october.swiftmailer_db.spool.class%">
<argument type="service" id="doctrine" />
<argument>%white_october.swiftmailer_db.spool.entity_class%</argument>
<argument>%kernel.environment%</argument>
<argument>%white_october.swiftmailer_db.spool.keep_sent_messages%</argument>
diff --git a/Spool/DatabaseSpool.php b/Spool/DatabaseSpool.php index 8836897..146a4c6 100644 --- a/Spool/DatabaseSpool.php +++ b/Spool/DatabaseSpool.php @@ -2,15 +2,21 @@
namespace WhiteOctober\SwiftMailerDBBundle\Spool;
+use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\ORM\EntityManager; +use Symfony\Bridge\Doctrine\RegistryInterface; use WhiteOctober\SwiftMailerDBBundle\EmailInterface;
+/**
protected $doc;
/**
/**
$this->doc = $doc;
$this->keepSentMessages = $keepSentMessages;
$obj = new $entityClass;
@@ -86,12 +92,8 @@ class DatabaseSpool extends \Swift_ConfigurableSpool $mailObject->setMessage(serialize($message)); $mailObject->setStatus(EmailInterface::STATUS_READY); $mailObject->setEnvironment($this->environment);
$this->doc->getManager()->flush();
return true;
} @@ -111,13 +113,13 @@ class DatabaseSpool extends \Swift_ConfigurableSpool $transport->start(); }
$repoClass = $this->em->getRepository($this->entityClass);
$this->doc->getManager()->flush();
$message = unserialize($email->getMessage());
$count += $transport->send($message, $failedRecipients);
if ($this->keepSentMessages === true) {
$email->setStatus(EmailInterface::STATUS_COMPLETE);
$this->doc->getManager()->flush();
if ($this->getTimeLimit() && (time() - $time) >= $this->getTimeLimit()) {
break;
@@ -149,3 +149,4 @@ class DatabaseSpool extends \Swift_ConfigurableSpool return $count; } }
1.8.1.msysgit.1
You need to use a reference to 'doctrine' and ->getManager() instead of using the original manager. That way when a database exception occurs, the manager can be reset and the previous DBAL exception can be emailed.