Commit b74ffac6 authored by Simon Gadient's avatar Simon Gadient

[FEATURE] Spool for TYPO3.SwiftMailer

Initial commit that overrides the Neos SwiftMailer package with a
spooler and adds a command to send the messages from the queue.

refs KIME-3340
parents
<?php
namespace WE\SwiftMailerSpool\Command;
/* *
* This script belongs to the Flow package "SwiftMailerSpool". *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License, either version 3 *
* of the License, or (at your option) any later version. *
* *
* The TYPO3 project - inspiring people to share! *
* */
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Cli\CommandController;
/**
* Spool Command Controller for the SwiftMailerSpool package
*
* @author Simon Gadient <simon@web-essentials.asia>
*/
class SwiftMailerSpoolCommandController extends CommandController {
/**
* @Flow\Inject
* @var \TYPO3\SwiftMailer\MailerInterface
*/
protected $spoolMailer;
/**
* @Flow\Inject
* @var \TYPO3\SwiftMailer\TransportFactory
*/
protected $transportFactory;
/**
* @Flow\Inject
* @var \TYPO3\Flow\Configuration\ConfigurationManager
* @internal
*/
protected $configurationManager;
/**
* Flush the email spool queue
*
* @throws \TYPO3\SwiftMailer\Exception
*/
public function flushCommand() {
$settings = $this->configurationManager->getConfiguration(\TYPO3\Flow\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'TYPO3.SwiftMailer');
$realTransport = $this->transportFactory->create($settings['transport']['type'], $settings['transport']['options'], $settings['transport']['arguments']);
/** @var \Swift_Spool $spool */
$spool = $this->spoolMailer->getTransport()->getSpool();
$sent = $spool->flushQueue($realTransport);
$this->outputLine($sent . ' mails sent');
}
}
<?php
namespace WE\SwiftMailerSpool;
/* *
* This script belongs to the Flow package "SwiftMailerSpool". *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License, either version 3 *
* of the License, or (at your option) any later version. *
* *
* The TYPO3 project - inspiring people to share! *
* */
/**
* Exception for the SwiftMailerSpool package
*
* @author Simon Gadient <simon@web-essentials.asia>
*/
class Exception extends \Exception {
}
<?php
namespace WE\SwiftMailerSpool;
/* *
* This script belongs to the Flow package "SwiftMailerSpool". *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License, either version 3 *
* of the License, or (at your option) any later version. *
* *
* The TYPO3 project - inspiring people to share! *
* */
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Reflection\ObjectAccess;
/**
* Spool transport factory for the SwiftMailerSpool package
*
* @author Simon Gadient <simon@web-essentials.asia>
*/
class SpoolTransportFactory {
/**
* @Flow\Inject
* @var \TYPO3\SwiftMailer\TransportFactory
*/
protected $transportFactory;
/**
* Factory method which create a spool transport with the given options.
*
* @param string $spoolType Object name of the spool to be used
* @param array $spoolOptions Options for the spool
* @param array $spoolArguments Constructor arguments for the spool
* @return \WE\SwiftMailerSpool\SpoolTransportInterface The created spool transport instance
* @throws Exception
*/
public function create($spoolType, array $spoolOptions = array(), array $spoolArguments = NULL) {
if (!class_exists($spoolType)) {
throw new Exception('The specified spool "' . $spoolType . '" does not exist.', 1269351207);
}
if (is_array($spoolArguments)) {
$class = new \ReflectionClass($spoolType);
$spool = $class->newInstanceArgs($spoolArguments);
} else {
$spool = new $spoolType();
}
foreach ($spoolOptions as $optionName => $optionValue) {
if (ObjectAccess::isPropertySettable($spool, $optionName)) {
ObjectAccess::setProperty($spool, $optionName, $optionValue);
}
}
$transport = $this->transportFactory->create('Swift_SpoolTransport', array(), array('spool' => $spool));
return $transport;
}
}
<?php
namespace WE\SwiftMailerSpool;
/* *
* This script belongs to the Flow package "SwiftMailerSpool". *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License, either version 3 *
* of the License, or (at your option) any later version. *
* *
* The TYPO3 project - inspiring people to share! *
* */
use TYPO3\SwiftMailer\TransportInterface;
/**
* SpoolTransport interface for the SwiftMailerSpool package
*
* @author Simon Gadient <simon@web-essentials.asia>
*/
interface SpoolTransportInterface extends TransportInterface {
}
WE\SwiftMailerSpool\SpoolTransportInterface:
scope: prototype
factoryObjectName: WE\SwiftMailerSpool\SpoolTransportFactory
arguments:
1:
setting: WE.SwiftMailerSpool.spool.type
2:
setting: WE.SwiftMailerSpool.spool.options
3:
setting: WE.SwiftMailerSpool.spool.arguments
TYPO3\SwiftMailer\MailerInterface:
arguments:
1:
object: WE\SwiftMailerSpool\SpoolTransportInterface
WE:
SwiftMailerSpool:
spool:
type: 'Swift_FileSpool'
options: []
arguments:
path: %FLOW_PATH_DATA%/SwiftMailerSpool/
{
"name": "we/swiftmailerspool",
"type": "typo3-flow-package",
"description": "A Flow package to extend the Neos Swift Mailer by a spool for asynchronous mailing",
"license": ["LGPL-3.0", "MIT"],
"require": {
"typo3/flow": "*",
"typo3/swiftmailer": "5.3.*"
},
"autoload": {
"psr-0": {
"WE\\SwiftMailerSpool": "Classes"
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment