Skip to content

Commit

Permalink
Merge branch 'hotfix/1.5.14'
Browse files Browse the repository at this point in the history
  • Loading branch information
richardhj committed Aug 21, 2020
2 parents 5bf7378 + 091bf71 commit 4901e51
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 12 deletions.
34 changes: 34 additions & 0 deletions classes/tl_nc_gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace NotificationCenter;

use Haste\Dca\PaletteManipulator;
use NotificationCenter\Gateway\LabelCallbackInterface;
use NotificationCenter\Model\Gateway;

Expand All @@ -23,6 +24,39 @@ public function loadSettingsLanguageFile()
\System::loadLanguageFile('tl_settings');
}

public function loadPalette($dc)
{
$paletteManipulator = PaletteManipulator::create();

$paletteManipulator->addLegend('gateway_legend', 'title_legend');

// Add the "email_overrideSmtp" field in Contao <4.10
if (version_compare(VERSION, '4.10', '<')) {
$paletteManipulator
->addField('email_overrideSmtp', 'gateway_legend', PaletteManipulator::POSITION_APPEND)
->applyToPalette('email', 'tl_nc_gateway')
;
return;
}

// Show the legacy field "email_overrideSmtp" as long as it is configured
$gatewayModel = Gateway::findByPk($dc->id);
if (null !== $gatewayModel && 'email' === $gatewayModel->type && $gatewayModel->email_overrideSmtp) {
$paletteManipulator
->addField('email_overrideSmtp', 'gateway_legend', PaletteManipulator::POSITION_APPEND)
->addField('mailerTransport', 'gateway_legend', PaletteManipulator::POSITION_APPEND)
->applyToPalette('email', 'tl_nc_gateway')
;
return;
}

// Just show the "mailerTransport" field instead of the "email_overrideSmtp"
$paletteManipulator
->addField('mailerTransport', 'gateway_legend', PaletteManipulator::POSITION_APPEND)
->applyToPalette('email', 'tl_nc_gateway')
;
}

/**
* Validate the queue delay
*
Expand Down
1 change: 1 addition & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
$GLOBALS['TL_HOOKS']['updatePersonalData'][] = array('NotificationCenter\ContaoHelper', 'sendPersonalDataEmail');
$GLOBALS['TL_HOOKS']['getUserNavigation'][] = array('NotificationCenter\ContaoHelper', 'addQueueToUserNavigation');
$GLOBALS['TL_HOOKS']['activateAccount'][] = array('NotificationCenter\ContaoHelper', 'sendActivationEmail');
$GLOBALS['TL_HOOKS']['getSystemMessages'][] = array('NotificationCenter\ContaoHelper', 'alertLegacySmtpSetting');

/**
* Queue manager
Expand Down
13 changes: 11 additions & 2 deletions dca/tl_nc_gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
'enableVersioning' => true,
'onload_callback' => array
(
array('NotificationCenter\tl_nc_gateway', 'loadSettingsLanguageFile')
array('NotificationCenter\tl_nc_gateway', 'loadSettingsLanguageFile'),
array('NotificationCenter\tl_nc_gateway', 'loadPalette')
),
'onsubmit_callback' => array
(
Expand Down Expand Up @@ -98,7 +99,7 @@
'__selector__' => array('type', 'queue_cronEnable', 'email', 'email_overrideSmtp', 'file_connection'),
'default' => '{title_legend},title,type',
'queue' => '{title_legend},title,type;{gateway_legend},queue_targetGateway,queue_delay;{cronjob_legend},queue_cronExplanation,queue_cronEnable',
'email' => '{title_legend},title,type;{gateway_legend},email_overrideSmtp,',
'email' => '{title_legend},title,type',
'file' => '{title_legend},title,type;{gateway_legend},file_type,file_connection',
'postmark' => '{title_legend},title,type;{gateway_legend},postmark_key,postmark_test,postmark_ssl',
),
Expand Down Expand Up @@ -251,6 +252,14 @@
'eval' => array('mandatory'=>true, 'rgxp'=>'digit', 'nospace'=>true, 'tl_class'=>'w50'),
'sql' => "varchar(16) NOT NULL default ''"
),
'mailerTransport' => array
(
'exclude' => true,
'inputType' => 'select',
'eval' => array('tl_class'=>'w50', 'includeBlankOption'=>true),
'options_callback' => array(\Contao\CoreBundle\Mailer\AvailableTransports::class, 'getTransportOptions'),
'sql' => "varchar(255) NOT NULL default ''"
),
'file_type' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_nc_gateway']['file_type'],
Expand Down
10 changes: 10 additions & 0 deletions languages/en/default.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file datatype="php" date="2018-10-22T10:57:28+02:00" original="default" source-language="en">
<body>
<trans-unit id="MSC.notification_center.warn_legacy_smtp">
<source>[Notification Center]: Using custom SMTP settings has been changed in Contao 4.10. Please visit &lt;a href=&quot;https://docs.contao.org/manual/en/system/settings/#different-e-mail-configurations-and-sender-addresses&quot;&gt;the documentation&lt;/a&gt; to learn how to define SMTP settings. Then, please update all email gateways that need this feature and disable "Override SMTP settings".</source>
</trans-unit>
</body>
</file>
</xliff>
8 changes: 8 additions & 0 deletions languages/en/tl_nc_gateway.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@
<source>This gateway will take the Contao e-mail settings by default. If you want to override the SMTP settings for this specific gateway, activate this checkbox.</source>
<target>This gateway will take the Contao e-mail settings by default. If you want to override the SMTP settings for this specific gateway, activate this checkbox.</target>
</trans-unit>
<trans-unit id="tl_nc_gateway.mailerTransport.0">
<source>Mailer transport</source>
<target>Mailer transport</target>
</trans-unit>
<trans-unit id="tl_nc_gateway.mailerTransport.1">
<source>Here you can override the mailer transport used to send e-mails.</source>
<target>Here you can override the mailer transport used to send e-mails.</target>
</trans-unit>
<trans-unit id="tl_nc_gateway.file_type.0">
<source>File type</source>
<target>File type</target>
Expand Down
23 changes: 23 additions & 0 deletions library/NotificationCenter/ContaoHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
namespace NotificationCenter;


use NotificationCenter\Model\Gateway;

class ContaoHelper extends \Controller
{
/**
Expand Down Expand Up @@ -166,4 +168,25 @@ public function addQueueToUserNavigation($arrModules, $blnShowAll)

return $arrModules;
}

/**
* Show a warning if legacy SMTP settings are defined in Contao 4.10.
* Hook: getSystemMessages
*/
public function alertLegacySmtpSetting()
{
if (version_compare(VERSION, '4.10', '<') && $this->objModel->email_overrideSmtp) {
return '';
}

$legacyGateways = Gateway::findBy(["type='email'", "email_overrideSmtp='1'"], []);
if (null === $legacyGateways) {
return '';
}

return sprintf(
'<p class="tl_error">%s</p>',
$GLOBALS['TL_LANG']['MSC']['notification_center']['warn_legacy_smtp']
);
}
}
34 changes: 25 additions & 9 deletions library/NotificationCenter/Gateway/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@ public function createDraft(Message $objMessage, array $arrTokens, $strLanguage
return new EmailMessageDraft($objMessage, $objLanguage, $arrTokens);
}

/**
* @param EmailMessageDraft $objDraft
*/
public function sendDraft(EmailMessageDraft $objDraft)
private function instantiateEmail()
{
if (version_compare(VERSION, '4.10', '>=')) {
$objEmail = new \Email();
if ($this->objModel->mailerTransport) {
$objEmail->addHeader('X-Transport', $this->objModel->mailerTransport);
}

return $objEmail;
}

// Override SMTP settings if desired
if (version_compare(VERSION, '4.4', '>=') && $this->objModel->email_overrideSmtp) {
if (method_exists(\Swift_SmtpTransport::class, 'newInstance')) {
Expand All @@ -71,13 +77,23 @@ public function sendDraft(EmailMessageDraft $objDraft)
$transport->setUsername($this->objModel->email_smtpUser)->setPassword($this->objModel->email_smtpPass);
}

$objEmail = new \Email(new \Swift_Mailer($transport));
} else {
$this->overrideSMTPSettings();
$objEmail = new \Email();
$this->resetSMTPSettings();
return new \Email(new \Swift_Mailer($transport));
}

$this->overrideSMTPSettings();
$objEmail = new \Email();
$this->resetSMTPSettings();

return $objEmail;
}

/**
* @param EmailMessageDraft $objDraft
*/
public function sendDraft(EmailMessageDraft $objDraft)
{
$objEmail = $this->instantiateEmail();

// Set priority
$objEmail->priority = $objDraft->getPriority();

Expand Down
4 changes: 3 additions & 1 deletion library/NotificationCenter/Model/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

namespace NotificationCenter\Model;

class Notification extends \Model
use Contao\Model;

class Notification extends Model
{

/**
Expand Down

0 comments on commit 4901e51

Please sign in to comment.