From 14f822ceff61c4d55fb679dbc84b2d128b02e8ae Mon Sep 17 00:00:00 2001 From: Frank Naegler <frank.naegler@typo3.org> Date: Sun, 26 Mar 2017 15:35:20 +0200 Subject: [PATCH] [TASK] Add preset for mail SMTP settings in install tool The current mail presets only allow to modify sendmail settings, but it's not possible to configure SMTP settings. Resolves: #80457 Releases: master Change-Id: Ib70351c9048c0ceec2b2a585d43a3ad04c81424e Reviewed-on: https://review.typo3.org/52167 Tested-by: TYPO3com <no-reply@typo3.com> Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl> Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org> Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org> Reviewed-by: Benni Mack <benni@typo3.org> Tested-by: Benni Mack <benni@typo3.org> --- .../Configuration/Mail/CustomPreset.php | 5 ++ .../Configuration/Mail/MailFeature.php | 1 + .../Configuration/Mail/SendmailPreset.php | 10 ++- .../Classes/Configuration/Mail/SmtpPreset.php | 75 +++++++++++++++++++ .../Tool/Configuration/Mail/Custom.html | 5 +- .../Tool/Configuration/Mail/Sendmail.html | 5 +- .../Action/Tool/Configuration/Mail/Smtp.html | 29 +++++++ 7 files changed, 123 insertions(+), 7 deletions(-) create mode 100644 typo3/sysext/install/Classes/Configuration/Mail/SmtpPreset.php create mode 100644 typo3/sysext/install/Resources/Private/Partials/Action/Tool/Configuration/Mail/Smtp.html diff --git a/typo3/sysext/install/Classes/Configuration/Mail/CustomPreset.php b/typo3/sysext/install/Classes/Configuration/Mail/CustomPreset.php index 7ae79c69d547..b860dc4d7ff1 100644 --- a/typo3/sysext/install/Classes/Configuration/Mail/CustomPreset.php +++ b/typo3/sysext/install/Classes/Configuration/Mail/CustomPreset.php @@ -25,6 +25,11 @@ class CustomPreset extends Configuration\AbstractCustomPreset implements Configu * @var array Configuration values handled by this preset */ protected $configurationValues = [ + 'MAIL/transport' => '', 'MAIL/transport_sendmail_command' => '', + 'MAIL/transport_smtp_server' => '', + 'MAIL/transport_smtp_encrypt' => '', + 'MAIL/transport_smtp_username' => '', + 'MAIL/transport_smtp_password' => '', ]; } diff --git a/typo3/sysext/install/Classes/Configuration/Mail/MailFeature.php b/typo3/sysext/install/Classes/Configuration/Mail/MailFeature.php index 3a059184048e..b54385bd1698 100644 --- a/typo3/sysext/install/Classes/Configuration/Mail/MailFeature.php +++ b/typo3/sysext/install/Classes/Configuration/Mail/MailFeature.php @@ -31,6 +31,7 @@ class MailFeature extends Configuration\AbstractFeature implements Configuration */ protected $presetRegistry = [ SendmailPreset::class, + SmtpPreset::class, CustomPreset::class, ]; } diff --git a/typo3/sysext/install/Classes/Configuration/Mail/SendmailPreset.php b/typo3/sysext/install/Classes/Configuration/Mail/SendmailPreset.php index d0d0263fe64a..9ffe54094ebd 100644 --- a/typo3/sysext/install/Classes/Configuration/Mail/SendmailPreset.php +++ b/typo3/sysext/install/Classes/Configuration/Mail/SendmailPreset.php @@ -35,8 +35,13 @@ class SendmailPreset extends Configuration\AbstractPreset * @var array Configuration values handled by this preset */ protected $configurationValues = [ + 'MAIL/transport' => 'sendmail', 'MAIL/transport_sendmail_command' => '', - ]; + 'MAIL/transport_smtp_server' => '', + 'MAIL/transport_smtp_encrypt' => '', + 'MAIL/transport_smtp_username' => '', + 'MAIL/transport_smtp_password' => '', + ]; /** * Get configuration values to activate prefix @@ -47,6 +52,9 @@ class SendmailPreset extends Configuration\AbstractPreset { $configurationValues = $this->configurationValues; $configurationValues['MAIL/transport_sendmail_command'] = $this->getSendmailPath(); + if ($this->postValues['Mail']['enable'] === 'Sendmail') { + $configurationValues['MAIL/transport'] = 'sendmail'; + } return $configurationValues; } diff --git a/typo3/sysext/install/Classes/Configuration/Mail/SmtpPreset.php b/typo3/sysext/install/Classes/Configuration/Mail/SmtpPreset.php new file mode 100644 index 000000000000..fb4895b87fc4 --- /dev/null +++ b/typo3/sysext/install/Classes/Configuration/Mail/SmtpPreset.php @@ -0,0 +1,75 @@ +<?php +namespace TYPO3\CMS\Install\Configuration\Mail; + +/* + * This file is part of the TYPO3 CMS project. + * + * It is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, either version 2 + * of the License, or any later version. + * + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + * + * The TYPO3 project - inspiring people to share! + */ + +use TYPO3\CMS\Install\Configuration; + +/** + * SMTP settings handling preset + */ +class SmtpPreset extends Configuration\AbstractPreset +{ + /** + * @var string Name of preset + */ + protected $name = 'Smtp'; + + /** + * @var int Priority of preset + */ + protected $priority = 40; + + /** + * @var array Configuration values handled by this preset + */ + protected $configurationValues = [ + 'MAIL/transport' => 'smtp', + 'MAIL/transport_sendmail_command' => '', + 'MAIL/transport_smtp_server' => 'localhost:25', + 'MAIL/transport_smtp_encrypt' => '', + 'MAIL/transport_smtp_username' => '', + 'MAIL/transport_smtp_password' => '', + ]; + + /** + * Get configuration values to activate prefix + * + * @return array Configuration values needed to activate prefix + */ + public function getConfigurationValues() + { + $configurationValues = $this->configurationValues; + $keys = array_keys($configurationValues); + foreach ($keys as $key) { + if (!empty($this->postValues['Smtp'][$key])) { + $configurationValues[$key] = $this->postValues['Smtp'][$key]; + } + } + if ($this->postValues['Mail']['enable'] === 'Smtp') { + $configurationValues['MAIL/transport'] = 'smtp'; + } + return $configurationValues; + } + + /** + * Check if sendmail path if set + * + * @return bool TRUE if sendmail path if set + */ + public function isAvailable() + { + return true; + } +} diff --git a/typo3/sysext/install/Resources/Private/Partials/Action/Tool/Configuration/Mail/Custom.html b/typo3/sysext/install/Resources/Private/Partials/Action/Tool/Configuration/Mail/Custom.html index ce19ff34de9f..b01192983068 100644 --- a/typo3/sysext/install/Resources/Private/Partials/Action/Tool/Configuration/Mail/Custom.html +++ b/typo3/sysext/install/Resources/Private/Partials/Action/Tool/Configuration/Mail/Custom.html @@ -21,10 +21,7 @@ </div> </div> <div class="message-body>"> - <p> - Custom sendmail command: - </p> - + <p>Custom mail settings:</p> <f:for each="{preset.configurationValues}" as="configurationValue" key="configurationKey"> <div class="form-group"> <label class="col-sm-6 control-label" for="{feature.name}{preset.name}{configurationKey}">{configurationKey}</label> diff --git a/typo3/sysext/install/Resources/Private/Partials/Action/Tool/Configuration/Mail/Sendmail.html b/typo3/sysext/install/Resources/Private/Partials/Action/Tool/Configuration/Mail/Sendmail.html index 8f7fa0290949..b33776c24078 100644 --- a/typo3/sysext/install/Resources/Private/Partials/Action/Tool/Configuration/Mail/Sendmail.html +++ b/typo3/sysext/install/Resources/Private/Partials/Action/Tool/Configuration/Mail/Sendmail.html @@ -24,10 +24,11 @@ <div class="message-body>"> <f:if condition="{preset.isAvailable}"> <f:then> - If you enable this setting the sendmail command will be set to: <pre>{preset.sendmailPath}</pre> + <p>If you enable this setting the sendmail command will be set to:</p> + <p><pre>{preset.sendmailPath}</pre></p> </f:then> <f:else> - Sendmail was not found in your PHP settings. + <p>Sendmail was not found in your PHP settings.</p> </f:else> </f:if> </div> diff --git a/typo3/sysext/install/Resources/Private/Partials/Action/Tool/Configuration/Mail/Smtp.html b/typo3/sysext/install/Resources/Private/Partials/Action/Tool/Configuration/Mail/Smtp.html new file mode 100644 index 000000000000..133bf161c5df --- /dev/null +++ b/typo3/sysext/install/Resources/Private/Partials/Action/Tool/Configuration/Mail/Smtp.html @@ -0,0 +1,29 @@ +<div class="alert {f:if(condition:'{preset.isAvailable}', then:'alert-success', else:'alert-danger')}"> + <div class="header-container"> + <div class="message-header"> + <input + type="radio" + class="t3-install-tool-configuration-radio" + id="t3-install-tool-configuration-mail-smtp" + name="install[values][{feature.name}][enable]" + value="{preset.name}" + {f:if(condition:'{preset.isAvailable}', then:'', else:'disabled="disabled"')} + {f:if(condition: preset.isActive, then:'checked="checked"')} + /> + <label + for="t3-install-tool-configuration-mail-smtp" + class="t3-install-tool-configuration-radio-label" + > + <strong> + SMTP Settings + </strong> + {f:if(condition: preset.isActive, then:' [Active]')} + </label> + </div> + </div> + <div class="message-body>"> + <p>To set up the mailer agent in TYPO3 CMS to use SMTP it's necessary to configure a SMTP server that will take care of the delivery of your emails. + Luckily, the configuration of a SMTP server is generally very easy. This option set some default values for you.</p> + </div> +</div> +<p></p> -- GitLab