Skip to content

Commit

Permalink
Workaround, waiting for symfony/swiftmailer-bundle#64 to be merged
Browse files Browse the repository at this point in the history
  • Loading branch information
BitOne committed Oct 23, 2013
1 parent a2794c9 commit 02c5973
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Command/BatchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
)
);
}

// FIXME: Workaround, waiting for https://github.com/symfony/SwiftmailerBundle/pull/64
// to be merged
$this->flushMailQueue();
}

/**
Expand Down Expand Up @@ -208,4 +212,35 @@ private function decodeConfiguration($data)

throw new \InvalidArgumentException($error);
}

/**
* @see Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener::onKernelTerminate
* and https://github.com/symfony/SwiftmailerBundle/pull/64
*/
public function flushMailQueue()
{
if (!$this->getContainer()->has('mailer')) {
return;
}

$mailers = array_keys($this->getContainer()->getParameter('swiftmailer.mailers'));
foreach ($mailers as $name) {
if ($this->getContainer() instanceof IntrospectableContainerInterface ?
$this->getContainer()->initialized(sprintf('swiftmailer.mailer.%s', $name)) : true) {
if ($this->getContainer()->getParameter(sprintf('swiftmailer.mailer.%s.spool.enabled', $name))) {
$mailer = $this->getContainer()->get(sprintf('swiftmailer.mailer.%s', $name));
$transport = $mailer->getTransport();
if ($transport instanceof \Swift_Transport_SpoolTransport) {
$spool = $transport->getSpool();
if ($spool instanceof \Swift_MemorySpool) {
$spool->flushQueue(
$this->getContainer()->get(sprintf('swiftmailer.mailer.%s.transport.real', $name))
);
}
}
}
}
}

}
}

0 comments on commit 02c5973

Please sign in to comment.