Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] View notice about required configuration in backend module #10

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions Classes/Controller/MailqueueModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace CPSIT\Typo3Mailqueue\Controller;

use CPSIT\Typo3Mailqueue\Enums;
use CPSIT\Typo3Mailqueue\Exception;
use CPSIT\Typo3Mailqueue\Mail;
use CPSIT\Typo3Mailqueue\Traits;
use Psr\Http\Message;
Expand Down Expand Up @@ -58,12 +59,14 @@ public function __invoke(Message\ServerRequestInterface $request): Message\Respo
$template = $this->moduleTemplateFactory->create($request);
$transport = $this->mailer->getTransport();
$sendId = $request->getQueryParams()['send'] ?? null;
$templateVariables = [];

if ($transport instanceof Mail\Transport\QueueableTransport) {
$templateVariables = $this->resolveTemplateVariables($transport, $sendId);
} else {
$templateVariables['unsupportedTransport'] = $transport::class;
$templateVariables = [
'unsupportedTransport' => $this->getTransportFromMailConfiguration(),
'typo3Version' => $this->typo3Version->getMajorVersion(),
];
}

// @todo Remove once support for TYPO3 v11 is dropped
Expand Down Expand Up @@ -165,6 +168,32 @@ private function addLinkToConfigurationModule(Backend\Template\ModuleTemplate $t
$buttonBar->addButton($button);
}

/**
* @throws Exception\MailTransportIsNotConfigured
*/
private function getTransportFromMailConfiguration(): string
{
$mailConfiguration = $GLOBALS['TYPO3_CONF_VARS']['MAIL'] ?? null;

if (!is_array($mailConfiguration)) {
throw new Exception\MailTransportIsNotConfigured();
}

$spoolType = $mailConfiguration['transport_spool_type'] ?? null;

if (is_string($spoolType) && trim($spoolType) !== '') {
return $spoolType;
}

$transport = $mailConfiguration['transport'] ?? null;

if (is_string($transport) && trim($transport) !== '') {
return $transport;
}

throw new Exception\MailTransportIsNotConfigured();
}

/**
* @todo Remove once support for TYPO3 v11 is dropped
*
Expand Down
41 changes: 41 additions & 0 deletions Classes/Exception/MailTransportIsNotConfigured.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

/*
* This file is part of the TYPO3 CMS extension "mailqueue".
*
* Copyright (C) 2024 Elias Häußler <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

namespace CPSIT\Typo3Mailqueue\Exception;

/**
* MailTransportIsNotConfigured
*
* @author Elias Häußler <[email protected]>
* @license GPL-2.0-or-later
*/
final class MailTransportIsNotConfigured extends Exception
{
public function __construct()
{
parent::__construct(
'No mail transport is configured. Please provide mail configuration in $GLOBALS[\'TYPO3_CONF_VARS\'][\'MAIL\'].',
1709803814,
);
}
}
10 changes: 10 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@
<source>The mail was successfully sent.</source>
</trans-unit>

<trans-unit id="unsupportedTransport.docs.text">
<source>Read the %s to learn more about mail spoolers in TYPO3.</source>
</trans-unit>
<trans-unit id="unsupportedTransport.docs.linkText">
<source>official documentation</source>
</trans-unit>
<trans-unit id="unsupportedTransport.example.header">
<source>Example configuration</source>
</trans-unit>

<trans-unit id="modal.failureDetails.header">
<source>Transport failure details</source>
</trans-unit>
Expand Down
50 changes: 50 additions & 0 deletions Resources/Private/Partials/List/UnsupportedTransport.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:c="http://typo3.org/ns/TYPO3/CMS/Core/ViewHelpers"
data-namespace-typo3-fluid="true">

<f:be.infobox state="2"
title="{f:translate(key: 'alert.unsupportedTransport.title', extensionName: 'Mailqueue')}"
message="{f:translate(key: 'alert.unsupportedTransport.message', arguments: '{0: transport}', extensionName: 'Mailqueue')}"
/>

<f:variable name="docsLink"><f:spaceless>
<a href="https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Mail/Index.html#spooling"
target="_blank"
rel="noreferrer"
>{f:translate(key: 'unsupportedTransport.docs.linkText', extensionName: 'Mailqueue')}</a>
</f:spaceless></f:variable>

<p>
{f:translate(key: 'unsupportedTransport.docs.text', extensionName: 'Mailqueue', arguments: '{0: docsLink}') -> f:format.raw()}
</p>

<div class="card">
<div class="card-header">
<div class="card-icon">
<c:icon identifier="actions-file-edit" />
</div>
<div class="card-header-body">
<h2 class="card-title">{f:translate(key: 'unsupportedTransport.example.header', extensionName: 'Mailqueue')}</h2>
</div>
</div>
<div class="card-body">
<pre><code><f:spaceless>
$GLOBALS['TYPO3_CONF_VARS']['MAIL']['transport_spool_type'] = 'file';
$GLOBALS['TYPO3_CONF_VARS']['MAIL']['transport_spool_filepath'] = '/path/to/mailqueue';
</f:spaceless></code></pre>
</div>
<div class="card-footer">
<f:if condition="{typo3Version} >= 12">
<f:then>
<code>config/system/additional.php</code>
</f:then>
<f:else>
<f:comment><!-- @todo Remove once support for TYPO3 v11 is dropped --></f:comment>
<code>typo3conf/AdditionalConfiguration.php</code>
</f:else>
</f:if>
</div>
</div>


</html>
8 changes: 4 additions & 4 deletions Resources/Private/Templates/List.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ <h1>{f:translate(key: 'header.list', extensionName: 'Mailqueue')}</h1>

<f:if condition="{unsupportedTransport}">
<f:then>
<f:be.infobox state="2"
title="{f:translate(key: 'alert.unsupportedTransport.title', extensionName: 'Mailqueue')}"
message="{f:translate(key: 'alert.unsupportedTransport.message', arguments: '{0: unsupportedTransport}', extensionName: 'Mailqueue')}"
/>
<f:render partial="List/UnsupportedTransport" arguments="{
transport: unsupportedTransport,
typo3Version: typo3Version
}" />
</f:then>
<f:else>
<f:render partial="List/Queue" arguments="{
Expand Down
Loading