sforkowany z mirror/friendica
Add logging
rodzic
0b94b84dc7
commit
11c831945c
|
@ -11,6 +11,7 @@ use Friendica\Model\User;
|
|||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Object\Email;
|
||||
use Friendica\Object\EMail\IEmail;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* A base class for building new emails
|
||||
|
@ -26,6 +27,8 @@ abstract class MailBuilder
|
|||
protected $config;
|
||||
/** @var BaseURL */
|
||||
protected $baseUrl;
|
||||
/** @var LoggerInterface */
|
||||
protected $logger;
|
||||
|
||||
/** @var string */
|
||||
protected $headers;
|
||||
|
@ -42,11 +45,12 @@ abstract class MailBuilder
|
|||
/** @var int */
|
||||
protected $recipientUid = null;
|
||||
|
||||
public function __construct(L10n $l10n, BaseURL $baseUrl, IConfig $config)
|
||||
public function __construct(L10n $l10n, BaseURL $baseUrl, IConfig $config, LoggerInterface $logger)
|
||||
{
|
||||
$this->l10n = $l10n;
|
||||
$this->baseUrl = $baseUrl;
|
||||
$this->config = $config;
|
||||
$this->logger = $logger;
|
||||
|
||||
$hostname = $baseUrl->getHostname();
|
||||
if (strpos($hostname, ':')) {
|
||||
|
@ -97,6 +101,7 @@ abstract class MailBuilder
|
|||
try {
|
||||
$this->l10n = $user['language'] ? $this->l10n->withLang($user['language']) : $this->l10n;
|
||||
} catch (Exception $e) {
|
||||
$this->logger->warning('cannot use language.', ['user' => $user, 'exception' => $e]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
namespace Friendica\Util\EMailer;
|
||||
|
||||
use Exception;
|
||||
use Friendica\App;
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Core\Config\IConfig;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Builder for system-wide emails without any dependency to concrete entities (like items, activities, ..)
|
||||
|
@ -26,9 +26,10 @@ class SystemMailBuilder extends MailBuilder
|
|||
/** @var string */
|
||||
protected $siteAdmin;
|
||||
|
||||
public function __construct(L10n $l10n, BaseURL $baseUrl, IConfig $config, string $siteEmailAddress, string $siteName)
|
||||
public function __construct(L10n $l10n, BaseURL $baseUrl, IConfig $config, LoggerInterface $logger,
|
||||
string$siteEmailAddress, string $siteName)
|
||||
{
|
||||
parent::__construct($l10n, $baseUrl, $config);
|
||||
parent::__construct($l10n, $baseUrl, $config, $logger);
|
||||
|
||||
if ($this->config->get('config', 'admin_name')) {
|
||||
$this->siteAdmin = $l10n->t('%1$s, %2$s Administrator', $this->config->get('config', 'admin_name'), $siteName);
|
||||
|
|
|
@ -85,7 +85,7 @@ class Emailer
|
|||
*/
|
||||
public function newSystemMail()
|
||||
{
|
||||
return new SystemMailBuilder($this->l10n, $this->baseUrl, $this->config,
|
||||
return new SystemMailBuilder($this->l10n, $this->baseUrl, $this->config, $this->logger,
|
||||
$this->getSiteEmailAddress(), $this->getSiteEmailName());
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ use Friendica\Test\MockedTest;
|
|||
use Friendica\Test\Util\SampleMailBuilder;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
use Friendica\Util\EMailer\MailBuilder;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
/**
|
||||
* This class tests the "MailBuilder" (@see MailBuilder )
|
||||
|
@ -62,7 +63,7 @@ class MailBuilderTest extends MockedTest
|
|||
*/
|
||||
public function testBuilderInstance()
|
||||
{
|
||||
$builder = new SampleMailBuilder($this->l10n, $this->baseUrl, $this->config);
|
||||
$builder = new SampleMailBuilder($this->l10n, $this->baseUrl, $this->config, new NullLogger());
|
||||
|
||||
$this->assertInstanceOf(MailBuilder::class, $builder);
|
||||
}
|
||||
|
@ -82,7 +83,7 @@ class MailBuilderTest extends MockedTest
|
|||
*/
|
||||
public function testBuilderWithRawEmail()
|
||||
{
|
||||
$builder = new SampleMailBuilder($this->l10n, $this->baseUrl, $this->config);
|
||||
$builder = new SampleMailBuilder($this->l10n, $this->baseUrl, $this->config, new NullLogger());
|
||||
|
||||
$testEmail = $builder
|
||||
->withMessage('Subject', 'Html', 'text')
|
||||
|
@ -112,7 +113,7 @@ class MailBuilderTest extends MockedTest
|
|||
*/
|
||||
public function testBuilderWithEmptyMail()
|
||||
{
|
||||
$builder = new SampleMailBuilder($this->l10n, $this->baseUrl, $this->config);
|
||||
$builder = new SampleMailBuilder($this->l10n, $this->baseUrl, $this->config, new NullLogger());
|
||||
|
||||
$builder->build(true);
|
||||
}
|
||||
|
@ -125,7 +126,7 @@ class MailBuilderTest extends MockedTest
|
|||
*/
|
||||
public function testBuilderWithEmptySender()
|
||||
{
|
||||
$builder = new SampleMailBuilder($this->l10n, $this->baseUrl, $this->config);
|
||||
$builder = new SampleMailBuilder($this->l10n, $this->baseUrl, $this->config, new NullLogger());
|
||||
|
||||
$builder
|
||||
->withRecipient('test@friendica.local')
|
||||
|
@ -137,7 +138,7 @@ class MailBuilderTest extends MockedTest
|
|||
*/
|
||||
public function testBuilderWithoutMessage()
|
||||
{
|
||||
$builder = new SampleMailBuilder($this->l10n, $this->baseUrl, $this->config);
|
||||
$builder = new SampleMailBuilder($this->l10n, $this->baseUrl, $this->config, new NullLogger());
|
||||
|
||||
$testEmail = $builder
|
||||
->withRecipient('recipient@friendica.local')
|
||||
|
@ -158,7 +159,7 @@ class MailBuilderTest extends MockedTest
|
|||
*/
|
||||
public function testBuilderWithJustPreamble()
|
||||
{
|
||||
$builder = new SampleMailBuilder($this->l10n, $this->baseUrl, $this->config);
|
||||
$builder = new SampleMailBuilder($this->l10n, $this->baseUrl, $this->config, new NullLogger());
|
||||
|
||||
$testEmail = $builder
|
||||
->withRecipient('recipient@friendica.local')
|
||||
|
|
|
@ -5,12 +5,11 @@ namespace Friendica\Test\src\Util\Emailer;
|
|||
use Friendica\App\BaseURL;
|
||||
use Friendica\Core\Config\IConfig;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Object\EMail\IEmail;
|
||||
use Friendica\Test\MockedTest;
|
||||
use Friendica\Test\Util\SampleMailBuilder;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
use Friendica\Util\EMailer\MailBuilder;
|
||||
use Friendica\Util\EMailer\SystemMailBuilder;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
class SystemMailBuilderTest extends MockedTest
|
||||
{
|
||||
|
@ -50,7 +49,7 @@ class SystemMailBuilderTest extends MockedTest
|
|||
*/
|
||||
public function testBuilderInstance()
|
||||
{
|
||||
$builder = new SystemMailBuilder($this->l10n, $this->baseUrl, $this->config, 'moreply@friendica.local', 'FriendicaSite');
|
||||
$builder = new SystemMailBuilder($this->l10n, $this->baseUrl, $this->config, new NullLogger(), 'moreply@friendica.local', 'FriendicaSite');
|
||||
|
||||
$this->assertInstanceOf(MailBuilder::class, $builder);
|
||||
$this->assertInstanceOf(SystemMailBuilder::class, $builder);
|
||||
|
|
Ładowanie…
Reference in New Issue