Skip to content

Commit

Permalink
Merge pull request #34 from pluswerk/feature/typo3-10-compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanti authored Oct 7, 2020
2 parents 655ec40 + af017e0 commit 776c622
Show file tree
Hide file tree
Showing 25 changed files with 290 additions and 488 deletions.
23 changes: 8 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@ git:
matrix:
fast_finish: true
include:
- php: 7.0
env: TYPO3_VERSION=8.7.*
- php: 7.1
env: TYPO3_VERSION=8.7.*
- php: 7.2
env: TYPO3_VERSION=8.7.*
- php: 7.3
env: TYPO3_VERSION=9.5.*
allow_failures:
- php: nightly
env: TYPO3_VERSION=8.7.*
- php: 7.2
env: TYPO3_VERSION=10.4.*
- php: 7.3
env: TYPO3_VERSION=10.4.*
- php: 7.4
env: TYPO3_VERSION=10.4.*

services:
- mysql
Expand All @@ -24,13 +19,11 @@ cache:
directories:
- $HOME/.composer/cache


before_install:
- phpenv config-rm xdebug.ini || echo "xdebug not available"

install:
- bash pipeline.sh

script:
- ./vendor/bin/grumphp run
- composer test

after_success: bash <(curl -s https://codecov.io/bash) -f ./.Build/coverage.xml
12 changes: 8 additions & 4 deletions Classes/Command/TestMailCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*
***/

declare(strict_types=1);

namespace Pluswerk\MailLogger\Command;

use Pluswerk\MailLogger\Domain\Model\LoggableMailMessage;
Expand All @@ -28,12 +30,14 @@ protected function configure()
{
$this
->setDescription('Sends a test mail.')
->setHelp('This command sends a mail with your complete setup and logs it. Additionally you can provide a mail template key and test your template in the default language, of course without variables.')
->setHelp(
'This command sends a mail with your complete setup and logs it. Additionally you can provide a mail template key and test your template in the default language, of course without variables.'
)
->addArgument('addressto', InputArgument::REQUIRED, 'Mail Address to send this testmail to')
->addArgument('templatekey', InputArgument::OPTIONAL, 'Mail Template Key to test a mail template', '');
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$args = $input->getArguments();
if ($args['templatekey'] !== '') {
Expand All @@ -42,9 +46,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$mail = GeneralUtility::makeInstance(ObjectManager::class)->get(LoggableMailMessage::class);
$mail
->setSubject('Testmail')
->setBody('This is a testmail.');
->text('This is a testmail.');
}
$mail->addTo($args['addressto']);
$mail->send();
return $mail->send() ? 0 : 1;
}
}
13 changes: 10 additions & 3 deletions Classes/Controller/MailLogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
*
***/

declare(strict_types=1);

namespace Pluswerk\MailLogger\Controller;

use Pluswerk\MailLogger\Domain\Model\MailLog;
use Pluswerk\MailLogger\Domain\Repository\MailLogRepository;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;

/**
Expand All @@ -22,16 +25,20 @@ class MailLogController extends ActionController
{
/**
* @var \Pluswerk\MailLogger\Domain\Repository\MailLogRepository
* @inject
*/
protected $mailLogRepository;

public function injectMailLogRepository(MailLogRepository $mailLogRepository): void
{
$this->mailLogRepository = $mailLogRepository;
}

/**
* action dashboard
*
* @return void
*/
public function dashboardAction()
public function dashboardAction(): void
{
$this->view->assign('mailLogs', $this->mailLogRepository->findAll());
}
Expand All @@ -42,7 +49,7 @@ public function dashboardAction()
* @param \Pluswerk\MailLogger\Domain\Model\MailLog $mailLog
* @return void
*/
public function showAction(MailLog $mailLog)
public function showAction(MailLog $mailLog): void
{
$this->view->assign('mailLog', $mailLog);
}
Expand Down
20 changes: 4 additions & 16 deletions Classes/Domain/Model/AbstractModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*
***/

declare(strict_types=1);

namespace Pluswerk\MailLogger\Domain\Model;

use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
Expand All @@ -30,37 +32,23 @@ abstract class AbstractModel extends AbstractEntity
*/
protected $crdate = 0;

/**
* @return int
*/
public function getTstamp(): int
{
return $this->tstamp;
}

/**
* @param int $tstamp
* @return self
*/
public function setTstamp($tstamp)
public function setTstamp(int $tstamp): self
{
$this->tstamp = $tstamp;
return $this;
}

/**
* @return int
*/
public function getCrdate(): int
{
return $this->crdate;
}

/**
* @param int $crdate
* @return self
*/
public function setCrdate($crdate)
public function setCrdate(int $crdate): self
{
$this->crdate = $crdate;
return $this;
Expand Down
35 changes: 15 additions & 20 deletions Classes/Domain/Model/DebuggableMailMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,38 @@
*
***/

declare(strict_types=1);

namespace Pluswerk\MailLogger\Domain\Model;

use Pluswerk\MailLogger\Utility\ConfigurationUtility;
use TYPO3\CMS\Core\Mail\MailMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;

use function in_array;

/**
*/
class DebuggableMailMessage extends MailMessage
{

/**
* @var bool
*/
protected $debug = false;

/**
* send mail
*
* @return int the number of recipients who were accepted for delivery
*/
public function send()
public function send(): bool
{
$this->modifyMailForDebug();
return parent::send();
}

/**
* @param bool $debug
* @return $this
*/
public function setDebug($debug)
public function setDebug(bool $debug): self
{
$this->debug = $debug;
return $this;
}

/**
* @return void
*/
protected function modifyMailForDebug()
protected function modifyMailForDebug(): void
{
$settings = ConfigurationUtility::getCurrentModuleConfiguration('settings');
if (
Expand All @@ -63,7 +52,7 @@ protected function modifyMailForDebug()
$settings['debug']['mail']['enable'] &&
(
$settings['debug']['mail']['ip'] === '*' ||
\in_array($_SERVER['REMOTE_ADDR'], GeneralUtility::trimExplode(',', $settings['debug']['mail']['ip'], true), true)
in_array($_SERVER['REMOTE_ADDR'], GeneralUtility::trimExplode(',', $settings['debug']['mail']['ip'], true), true)
)
)
) {
Expand All @@ -75,7 +64,13 @@ protected function modifyMailForDebug()
$this->setTo(GeneralUtility::trimExplode(',', $settings['debug']['mail']['mailRedirect'], true));
$this->setCc([]);
$this->setBcc([]);
$this->setBody($this->getBody() . str_replace(' ', '&nbsp;&nbsp;', $messageSuffix));
$this->text($this->getFullBodyDebug() . str_replace(' ', '&nbsp;&nbsp;', $messageSuffix));
$this->html(null);
}
}

protected function getFullBodyDebug(): string
{
return implode('<br><br><br><br>', array_filter([$this->getTextBody(), $this->getHtmlBody()]));
}
}
54 changes: 22 additions & 32 deletions Classes/Domain/Model/LoggableMailMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
*
***/

declare(strict_types=1);

namespace Pluswerk\MailLogger\Domain\Model;

use Pluswerk\MailLogger\Domain\Repository\MailLogRepository;
use Symfony\Component\Mime\Address;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MailUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
Expand All @@ -29,12 +32,7 @@ class LoggableMailMessage extends DebuggableMailMessage
*/
protected $mailLog;

/**
* send mail
*
* @return int the number of recipients who were accepted for delivery
*/
public function send()
public function send(): bool
{
if (empty($this->getFrom())) {
$this->setFrom(MailUtility::getSystemFrom());
Expand All @@ -52,48 +50,40 @@ public function send()

// write result to log after send
$this->assignMailLog();
$this->mailLog->setResult($result);
$this->mailLog->setResult((string)$result);
$mailLogRepository->update($this->mailLog);
return $result;
}

/**
* @return MailLog
*/
public function getMailLog()
public function getMailLog(): MailLog
{
if ($this->mailLog === null) {
$this->mailLog = GeneralUtility::makeInstance(MailLog::class);
}
return $this->mailLog;
}

/**
* @return void
*/
protected function assignMailLog()
protected function assignMailLog(): void
{
$this->mailLog->setSubject($this->getSubject());
if ($this->getBody() !== null) {
$this->mailLog->setMessage($this->getBody());
} else {
$this->mailLog->setMessage($this->getBodiesOfChildren());
}
$this->mailLog->setMailFrom($this->getHeaders()->get('from') ? $this->getHeaders()->get('from')->getFieldBody() : '');
$this->mailLog->setMailTo($this->getHeaders()->get('to') ? $this->getHeaders()->get('to')->getFieldBody() : '');
$this->mailLog->setMailCopy($this->getHeaders()->get('cc') ? $this->getHeaders()->get('cc')->getFieldBody() : '');
$this->mailLog->setMailBlindCopy($this->getHeaders()->get('bcc') ? $this->getHeaders()->get('bcc')->getFieldBody() : '');
$this->mailLog->setMessage($this->getFullBodyDebug());
$this->mailLog->setMailFrom($this->addressesToString($this->getFrom()));
$this->mailLog->setMailTo($this->addressesToString($this->getTo()));
$this->mailLog->setMailCopy($this->addressesToString($this->getCc()));
$this->mailLog->setMailBlindCopy($this->addressesToString($this->getBcc()));
$this->mailLog->setHeaders($this->getHeaders()->toString());
}

protected function getBodiesOfChildren()
protected function addressesToString(array $addresses): string
{
$string = '';
if (!empty($this->getChildren())) {
foreach ($this->getChildren() as $child) {
$string .= $child->toString() . '<br><br><br><br>';
}
}
return utf8_decode(utf8_encode(quoted_printable_decode($string)));
return implode(
', ',
array_map(
function (Address $address) {
return $address->getName() . ' <' . $address->getAddress() . '>';
},
$addresses
)
);
}
}
Loading

0 comments on commit 776c622

Please sign in to comment.