Skip to content

Commit 834e17f

Browse files
committed
Workaround, waiting for symfony/swiftmailer-bundle#64 to be merged
1 parent 1995b63 commit 834e17f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Command/BatchCommand.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
137137
)
138138
);
139139
}
140+
141+
// FIXME: Workaround, waiting for https://github.com/symfony/SwiftmailerBundle/pull/64
142+
// to be merged
143+
$this->flushMailQueue();
140144
}
141145

142146
/**
@@ -208,4 +212,35 @@ private function decodeConfiguration($data)
208212

209213
throw new \InvalidArgumentException($error);
210214
}
215+
216+
/**
217+
* @see Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener::onKernelTerminate
218+
* and https://github.com/symfony/SwiftmailerBundle/pull/64
219+
*/
220+
public function flushMailQueue()
221+
{
222+
if (!$this->getContainer()->has('mailer')) {
223+
return;
224+
}
225+
226+
$mailers = array_keys($this->getContainer()->getParameter('swiftmailer.mailers'));
227+
foreach ($mailers as $name) {
228+
if ($this->getContainer() instanceof IntrospectableContainerInterface ?
229+
$this->getContainer()->initialized(sprintf('swiftmailer.mailer.%s', $name)) : true) {
230+
if ($this->getContainer()->getParameter(sprintf('swiftmailer.mailer.%s.spool.enabled', $name))) {
231+
$mailer = $this->getContainer()->get(sprintf('swiftmailer.mailer.%s', $name));
232+
$transport = $mailer->getTransport();
233+
if ($transport instanceof \Swift_Transport_SpoolTransport) {
234+
$spool = $transport->getSpool();
235+
if ($spool instanceof \Swift_MemorySpool) {
236+
$spool->flushQueue(
237+
$this->getContainer()->get(sprintf('swiftmailer.mailer.%s.transport.real', $name))
238+
);
239+
}
240+
}
241+
}
242+
}
243+
}
244+
245+
}
211246
}

0 commit comments

Comments
 (0)