Skip to content

Commit

Permalink
Merge branch 'release/25.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed Feb 2, 2024
2 parents eb119d7 + 28f6f1f commit fa5e113
Show file tree
Hide file tree
Showing 16 changed files with 306 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Classes/Controller/FrontendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function initializeUnsubscribe2Action(): void
{
$arguments = GeneralUtility::_GP('tx_luxletter_fe');
if (is_array($arguments)) {
$this->request->setArguments($arguments);
$this->request = $this->request->withArguments($arguments);
}
}

Expand Down
78 changes: 68 additions & 10 deletions Classes/Controller/NewsletterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);
namespace In2code\Luxletter\Controller;

use Doctrine\DBAL\Driver\Exception as ExceptionDbalDriver;
use In2code\Lux\Domain\Repository\VisitorRepository;
use In2code\Luxletter\Domain\Model\Dto\Filter;
use In2code\Luxletter\Domain\Model\Newsletter;
Expand All @@ -11,15 +12,23 @@
use In2code\Luxletter\Domain\Service\PreviewUrlService;
use In2code\Luxletter\Domain\Service\QueueService;
use In2code\Luxletter\Domain\Service\ReceiverAnalysisService;
use In2code\Luxletter\Events\AfterTestMailButtonClickedEvent;
use In2code\Luxletter\Exception\ApiConnectionException;
use In2code\Luxletter\Exception\AuthenticationFailedException;
use In2code\Luxletter\Exception\InvalidUrlException;
use In2code\Luxletter\Exception\MisconfigurationException;
use In2code\Luxletter\Mail\TestMail;
use In2code\Luxletter\Utility\BackendUserUtility;
use In2code\Luxletter\Utility\ConfigurationUtility;
use In2code\Luxletter\Utility\LocalizationUtility;
use In2code\Luxletter\Utility\ObjectUtility;
use JsonException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException;
use TYPO3\CMS\Fluid\View\StandaloneView;

class NewsletterController extends AbstractNewsletterController
Expand Down Expand Up @@ -220,36 +229,80 @@ public function wizardUserPreviewAjax(ServerRequestInterface $request): Response
return $response;
}

/**
* @param ServerRequestInterface $request
* @return ResponseInterface
* @throws AuthenticationFailedException
* @throws ExceptionDbalDriver
* @throws ApiConnectionException
* @throws InvalidUrlException
* @throws MisconfigurationException
* @throws JsonException
* @throws ExtensionConfigurationExtensionNotConfiguredException
* @throws ExtensionConfigurationPathDoesNotExistException
* @throws InvalidConfigurationTypeException
*/
public function testMailAjax(ServerRequestInterface $request): ResponseInterface
{
if (BackendUserUtility::isBackendUserAuthenticated() === false) {
throw new AuthenticationFailedException('You are not authenticated to send mails', 1560872725);
}
$testMail = GeneralUtility::makeInstance(TestMail::class);
$status = $testMail->preflight(
$request->getQueryParams()['origin'],
$request->getQueryParams()['layout'],
(int)$request->getQueryParams()['configuration'],
$request->getQueryParams()['subject'],
$request->getQueryParams()['email']
);
$status = null;

/**
* This event can be used for sending the Test-email with external logic
* @see Documentation/Tech/Events.md
*/
$event = GeneralUtility::makeInstance(AfterTestMailButtonClickedEvent::class, $request);
$this->eventDispatcher->dispatch($event);

if ($event->isTestMailIsSendExternal() === false) {
$testMail = GeneralUtility::makeInstance(TestMail::class);
$status = $testMail->preflight(
$request->getQueryParams()['origin'],
$request->getQueryParams()['layout'],
(int)$request->getQueryParams()['configuration'],
$request->getQueryParams()['subject'],
$request->getQueryParams()['email']
);
}
$responseData = [
'status' => $status ?? $event->getStatus(),
];
if ($event->isTestMailIsSendExternal()) {
$responseData += $event->getStatusResponse();
}
$response = ObjectUtility::getJsonResponse();
$response->getBody()->write(json_encode(['status' => $status]));
$response->getBody()->write(json_encode($responseData, JSON_THROW_ON_ERROR));
return $response;
}

/**
* @param ServerRequestInterface $request
* @return ResponseInterface
* @throws AuthenticationFailedException
* @throws ExceptionDbalDriver
* @throws ExtensionConfigurationExtensionNotConfiguredException
* @throws ExtensionConfigurationPathDoesNotExistException
* @throws InvalidConfigurationTypeException
* @throws MisconfigurationException
*/
public function previewSourcesAjax(ServerRequestInterface $request): ResponseInterface
{
if (BackendUserUtility::isBackendUserAuthenticated() === false) {
throw new AuthenticationFailedException('You are not authenticated to send mails', 1645707268);
}
$previewUrlService = GeneralUtility::makeInstance(PreviewUrlService::class);
$response = ObjectUtility::getJsonResponse();
$content = $previewUrlService->get($request->getQueryParams()['origin'], $request->getQueryParams()['layout']);
$response = ObjectUtility::getJsonResponse();
$response->getBody()->write(json_encode($content));
return $response;
}

/**
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
public function receiverDetailAjax(ServerRequestInterface $request): ResponseInterface
{
$userRepository = GeneralUtility::makeInstance(UserRepository::class);
Expand All @@ -270,6 +323,11 @@ public function receiverDetailAjax(ServerRequestInterface $request): ResponseInt
return $response;
}

/**
* @return void
* @throws ExtensionConfigurationExtensionNotConfiguredException
* @throws ExtensionConfigurationPathDoesNotExistException
*/
protected function addDocumentHeaderForNewsletterController(): void
{
$menuConfiguration = [
Expand Down
9 changes: 6 additions & 3 deletions Classes/Domain/Repository/LogRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,14 @@ public function findRawByUser(User $user, array $statusWhitelist = [], array $st
}

/**
* @param User $user
* @return QueryResultInterface
* @param ?User $user
* @return ?QueryResultInterface
*/
public function findByUser(User $user): QueryResultInterface
public function findByUser(?User $user): ?QueryResultInterface
{
if ($user === null) {
return null;
}
$query = $this->createQuery();
$query->matching($query->equals('user', $user));
$query->setLimit(100);
Expand Down
96 changes: 96 additions & 0 deletions Classes/Events/AfterTestMailButtonClickedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

declare(strict_types=1);
namespace In2code\Luxletter\Events;

use Psr\Http\Message\ServerRequestInterface;

final class AfterTestMailButtonClickedEvent
{
public const STATUS_SEVERITY_SUCCESS = 'alert-success';
public const STATUS_SEVERITY_WARNING = 'alert-warning';
public const STATUS_SEVERITY_ERROR = 'alert-danger';

protected ServerRequestInterface $request;

protected bool $testMailIsSendExternal = false;
protected bool $status = false;

protected string $statusTitle = '';
protected string $statusMessage = '';
protected string $statusSeverity = self::STATUS_SEVERITY_ERROR;

public function __construct(ServerRequestInterface $request)
{
$this->request = $request;
}

public function getRequest(): ServerRequestInterface
{
return $this->request;
}

public function isTestMailIsSendExternal(): bool
{
return $this->testMailIsSendExternal;
}

public function setTestMailIsSendExternal(): self
{
$this->testMailIsSendExternal = true;
return $this;
}

public function getStatus(): bool
{
return $this->status;
}

public function setStatus(bool $status): self
{
$this->status = $status;
return $this;
}

public function getStatusTitle(): string
{
return $this->statusTitle;
}

public function setStatusTitle(string $statusTitle): self
{
$this->statusTitle = $statusTitle;
return $this;
}

public function getStatusMessage(): string
{
return $this->statusMessage;
}

public function setStatusMessage(string $statusMessage): self
{
$this->statusMessage = $statusMessage;
return $this;
}

public function getStatusSeverity(): string
{
return $this->statusSeverity;
}

public function setStatusSeverity(string $statusSeverity): self
{
$this->statusSeverity = $statusSeverity;
return $this;
}

public function getStatusResponse(): array
{
return [
'statusTitle' => $this->getStatusTitle(),
'statusMessage' => $this->getStatusMessage(),
'statusSeverity' => $this->getStatusSeverity(),
];
}
}
35 changes: 35 additions & 0 deletions Classes/Events/BeforeBodytextIsParsedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);
namespace In2code\Luxletter\Events;

use In2code\Luxletter\Domain\Model\Queue;

final class BeforeBodytextIsParsedEvent
{
protected Queue $queue;

protected string $bodytext = '';

public function __construct(Queue $queue)
{
$this->queue = $queue;
$this->bodytext = $queue->getNewsletter()->getBodytext();
}

public function getQueue(): Queue
{
return $this->queue;
}

public function getBodytext(): string
{
return $this->bodytext;
}

public function setBodytext(string $bodytext): self
{
$this->bodytext = $bodytext;
return $this;
}
}
6 changes: 5 additions & 1 deletion Classes/Mail/ProgressQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use In2code\Luxletter\Domain\Service\BodytextManipulation\LinkHashing;
use In2code\Luxletter\Domain\Service\LogService;
use In2code\Luxletter\Domain\Service\Parsing\Newsletter;
use In2code\Luxletter\Events\BeforeBodytextIsParsedEvent;
use In2code\Luxletter\Events\ProgressQueueEvent;
use In2code\Luxletter\Exception\ArgumentMissingException;
use In2code\Luxletter\Exception\MisconfigurationException;
Expand Down Expand Up @@ -181,8 +182,11 @@ protected function getSubject(Queue $queue): string
*/
protected function getBodyText(Queue $queue): string
{
$event = GeneralUtility::makeInstance(BeforeBodytextIsParsedEvent::class, $queue);
$this->eventDispatcher->dispatch($event);

$bodytext = $this->parseService->parseBodytext(
$queue->getNewsletter()->getBodytext(),
$event->getBodytext(),
[
'user' => $queue->getUser(),
'newsletter' => $queue->getNewsletter(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ lib {
}

// Settings for EXT:news
tt_content {
news_pi1.templateName = NewsList
news_newsliststicky.templateName = NewsList
news_newsselectedlist.templateName = NewsList
}
plugin.tx_news {
view {
templateRootPaths {
Expand Down
1 change: 1 addition & 0 deletions Documentation/Changelog/Index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

| Version | Date | State | Description |
|------------|------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 25.0.0 | 2024.02.02 | Feature | Add two new events for newsletter manipulation, update LUXletter for news 11, bugfix for unsubscribe action in TYPO3 12 |
| 24.0.2 | 2023.10.05 | Bugfix | Respect `asynchronousQueueStorage` configuration even if newsletters are generated from CLI now |
| 24.0.1 | 2023.09.29 | Bugfix | Revive `$GLOBALS['TYPO3_CONF_VARS']['MAIL_LUXLETTER']` configuration for TYPO3 11 and 12 |
| 24.0.0 | 2023.09.05 | Feature | Add another unsubscribe plugin where the receiver can select his preferences |
Expand Down
1 change: 1 addition & 0 deletions Documentation/Index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Send newsletters the easy way
### Tech corner and FAQ

[Tech corner and FAQ](Tech/Index.md)
[Events](Tech/Events.md)

### Changelog and breaking changes

Expand Down
Loading

0 comments on commit fa5e113

Please sign in to comment.