Commit e44c7beb authored by Simon Gadient's avatar Simon Gadient
Browse files

[IMP] Add a logger to the spool command

refs KIME-3340
parent 80eecf34
Loading
Loading
Loading
Loading
+13 −2
Original line number Original line Diff line number Diff line
@@ -40,6 +40,12 @@ class SwiftMailerSpoolCommandController extends CommandController {
	 */
	 */
	protected $configurationManager;
	protected $configurationManager;


	/**
	 * @Flow\Inject
	 * @var \WE\SwiftMailerSpool\Log\SwiftMailerSpoolLoggerInterface
	 */
	protected $logger;

	/**
	/**
	 * Flush the email spool queue
	 * Flush the email spool queue
	 * 
	 * 
@@ -50,8 +56,13 @@ class SwiftMailerSpoolCommandController extends CommandController {
		$realTransport = $this->transportFactory->create($settings['transport']['type'], $settings['transport']['options'], $settings['transport']['arguments']);
		$realTransport = $this->transportFactory->create($settings['transport']['type'], $settings['transport']['options'], $settings['transport']['arguments']);
		/** @var \Swift_Spool $spool */
		/** @var \Swift_Spool $spool */
		$spool = $this->spoolMailer->getTransport()->getSpool();
		$spool = $this->spoolMailer->getTransport()->getSpool();
		$sent = $spool->flushQueue($realTransport);
		$failedRecipients = array();
		$this->outputLine($sent . ' mails sent');
		$sent = $spool->flushQueue($realTransport, $failedRecipients);
		$this->logger->log($sent . ' mails sent.');
		$count = count($failedRecipients);
		if ($count > 0) {
			$this->logger->log($count . ' recipients failed. Check the spool to see the messages.', LOG_WARNING);
		}
	}
	}


}
}
+20 −0
Original line number Original line Diff line number Diff line
<?php
namespace WE\SwiftMailerSpool\Log;

	/*                                                                        *
	 * 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!                         *
	 *                                                                        */

/**
 * Logger interface for the SwiftMailerSpool package
 *
 * @author Simon Gadient <simon@web-essentials.asia>
 */
interface SwiftMailerSpoolLoggerInterface extends \TYPO3\Flow\Log\LoggerInterface {
}
+13 −0
Original line number Original line Diff line number Diff line
@@ -13,3 +13,16 @@ TYPO3\SwiftMailer\MailerInterface:
  arguments:
  arguments:
    1:
    1:
      object: WE\SwiftMailerSpool\SpoolTransportInterface
      object: WE\SwiftMailerSpool\SpoolTransportInterface

WE\SwiftMailerSpool\Log\SwiftMailerSpoolLoggerInterface:
  scope: singleton
  factoryObjectName: TYPO3\Flow\Log\LoggerFactory
  arguments:
    1:
      value: 'SystemLogger'
    2:
      setting: TYPO3.Flow.log.systemLogger.logger
    3:
      setting: TYPO3.Flow.log.systemLogger.backend
    4:
      setting: TYPO3.Flow.log.systemLogger.backendOptions
+2 −2
Original line number Original line Diff line number Diff line
@@ -15,8 +15,8 @@ The package is pre-configured to use a the file spool:
## Usage
## Usage


Different from the [Neos Swift Mailer](https://github.com/neos/swiftmailer), a `\Swift_Message` has to be created instead 
Different from the [Neos Swift Mailer](https://github.com/neos/swiftmailer), a `\Swift_Message` has to be created instead 
of using the `\TYPO3\SwiftMailer\Message` object. This is due to a problems on the serialization of the message that 
of using the `\TYPO3\SwiftMailer\Message` object. This is due to a problem on the serialization of the message that 
happens in the `\FileSpool` as the serialized `\TYPO3\SwiftMailer\Message` does not include its parent properties of the 
happens in the `\FileSpool` as the serialized `\TYPO3\SwiftMailer\Message` does not include its private parent properties of the 
`\Swift_Message`. 
`\Swift_Message`. 


The process is the same as with the normal SwiftMailer library.
The process is the same as with the normal SwiftMailer library.