[TASK] Add preset for mail SMTP settings in install tool 67/52167/8
authorFrank Naegler <frank.naegler@typo3.org>
Sun, 26 Mar 2017 13:35:20 +0000 (15:35 +0200)
committerBenni Mack <benni@typo3.org>
Tue, 28 Mar 2017 11:27:16 +0000 (13:27 +0200)
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>
typo3/sysext/install/Classes/Configuration/Mail/CustomPreset.php
typo3/sysext/install/Classes/Configuration/Mail/MailFeature.php
typo3/sysext/install/Classes/Configuration/Mail/SendmailPreset.php
typo3/sysext/install/Classes/Configuration/Mail/SmtpPreset.php [new file with mode: 0644]
typo3/sysext/install/Resources/Private/Partials/Action/Tool/Configuration/Mail/Custom.html
typo3/sysext/install/Resources/Private/Partials/Action/Tool/Configuration/Mail/Sendmail.html
typo3/sysext/install/Resources/Private/Partials/Action/Tool/Configuration/Mail/Smtp.html [new file with mode: 0644]

index 7ae79c6..b860dc4 100644 (file)
@@ -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' => '',
     ];
 }
index 3a05918..b54385b 100644 (file)
@@ -31,6 +31,7 @@ class MailFeature extends Configuration\AbstractFeature implements Configuration
      */
     protected $presetRegistry = [
         SendmailPreset::class,
+        SmtpPreset::class,
         CustomPreset::class,
     ];
 }
index d0d0263..9ffe540 100644 (file)
@@ -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 (file)
index 0000000..fb4895b
--- /dev/null
@@ -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;
+    }
+}
index ce19ff3..b011929 100644 (file)
                </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>
index 8f7fa02..b33776c 100644 (file)
        <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 (file)
index 0000000..133bf16
--- /dev/null
@@ -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>