sampart / WhiteOctoberSwiftMailerDBBundle

A bundle to facilitate SwiftMailer spooling messages to a database
31 stars 18 forks source link

Can't email database exceptions because connection is closed when there is an error. #12

Closed ghost closed 9 years ago

ghost commented 9 years ago

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.

richsage commented 9 years ago

Thanks - could you possibly submit a PR? :-)

ghost commented 9 years ago

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%">

+use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\ORM\EntityManager; +use Symfony\Bridge\Doctrine\RegistryInterface; use WhiteOctober\SwiftMailerDBBundle\EmailInterface;

+/**