Add debug log message back

This commit is contained in:
Lukas Reschke 2015-03-16 13:01:17 +01:00
parent e32f1582c7
commit d7c7808a5e
3 changed files with 23 additions and 5 deletions

View File

@ -10,6 +10,7 @@ namespace OC\Mail;
use OCP\IConfig;
use OCP\Mail\IMailer;
use OCP\ILogger;
/**
* Class Mailer provides some basic functions to create a mail message that can be used in combination with
@ -34,15 +35,21 @@ class Mailer implements IMailer {
private $instance = null;
/** @var IConfig */
private $config;
/** @var ILogger */
private $logger;
/** @var \OC_Defaults */
private $defaults;
/**
* @param IConfig $config
* @param ILogger $logger
* @param \OC_Defaults $defaults
*/
function __construct(IConfig $config, \OC_Defaults $defaults) {
function __construct(IConfig $config,
ILogger $logger,
\OC_Defaults $defaults) {
$this->config = $config;
$this->logger = $logger;
$this->defaults = $defaults;
}
@ -67,12 +74,14 @@ class Mailer implements IMailer {
*/
public function send(Message $message) {
if (sizeof($message->getFrom()) === 0) {
$message->setFrom(array(\OCP\Util::getDefaultEmailAddress($this->defaults->getName())));
$message->setFrom([\OCP\Util::getDefaultEmailAddress($this->defaults->getName())]);
}
$failedRecipients = array();
$failedRecipients = [];
$this->getInstance()->send($message->getSwiftMessage(), $failedRecipients);
$logMessage = sprintf('Sent mail to "%s" with subject "%s"', print_r($message->getTo(), true), $message->getSubject());
$this->logger->debug($logMessage, ['app' => 'core']);
return $failedRecipients;
}

View File

@ -314,7 +314,11 @@ class Server extends SimpleContainer implements IServerContainer {
);
});
$this->registerService('Mailer', function(Server $c) {
return new Mailer($c->getConfig(), new \OC_Defaults());
return new Mailer(
$c->getConfig(),
$c->getLogger(),
new \OC_Defaults()
);
});
}

View File

@ -10,12 +10,15 @@ namespace Test;
use OC\Mail\Mailer;
use OCP\IConfig;
use OC_Defaults;
use OCP\ILogger;
class MailerTest extends TestCase {
/** @var IConfig */
private $config;
/** @var OC_Defaults */
private $defaults;
/** @var ILogger */
private $logger;
/** @var Mailer */
private $mailer;
@ -26,7 +29,9 @@ class MailerTest extends TestCase {
->disableOriginalConstructor()->getMock();
$this->defaults = $this->getMockBuilder('\OC_Defaults')
->disableOriginalConstructor()->getMock();
$this->mailer = new Mailer($this->config, $this->defaults);
$this->logger = $this->getMockBuilder('\OCP\ILogger')
->disableOriginalConstructor()->getMock();
$this->mailer = new Mailer($this->config, $this->logger, $this->defaults);
}
public function testGetMailInstance() {