From a660aad3d44c9c3c8ffe72c00eff0572536da915 Mon Sep 17 00:00:00 2001 From: Fritz Michael Gschwantner Date: Fri, 4 Sep 2020 15:16:23 +0100 Subject: [PATCH 1/4] automatically use the configured sendmail_path --- manager-bundle/src/ContaoManager/Plugin.php | 25 +++++++++++ .../tests/ContaoManager/PluginTest.php | 42 +++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/manager-bundle/src/ContaoManager/Plugin.php b/manager-bundle/src/ContaoManager/Plugin.php index 0480f72368b..bf2ca173c23 100644 --- a/manager-bundle/src/ContaoManager/Plugin.php +++ b/manager-bundle/src/ContaoManager/Plugin.php @@ -245,6 +245,7 @@ public function getExtensionConfig($extensionName, array $extensionConfigs, Plug case 'swiftmailer': $extensionConfigs = $this->checkMailerTransport($extensionConfigs, $container); + $extensionConfigs = $this->setSendmailCommand($extensionConfigs); if (!isset($_SERVER['MAILER_URL'])) { $container->setParameter('env(MAILER_URL)', $this->getMailerUrl($container)); @@ -372,6 +373,30 @@ private function getDatabaseUrl(ContainerBuilder $container): string ); } + /** + * Sets the sendmail command for Swiftmailer to the sendmail_path defined by PHP. + * + * @return array>>> + */ + private function setSendmailCommand(array $extensionConfigs): array + { + $sendmailPath = @ini_get('sendmail_path'); + + if (!$sendmailPath) { + return $extensionConfigs; + } + + foreach ($extensionConfigs as $extensionConfig) { + if (isset($extensionConfig['command']) || isset($extensionConfig['mailers']['default']['command'])) { + return $extensionConfigs; + } + } + + $extensionConfigs[] = ['command' => $sendmailPath]; + + return $extensionConfigs; + } + private function getMailerUrl(ContainerBuilder $container): string { if ('sendmail' === $container->getParameter('mailer_transport')) { diff --git a/manager-bundle/tests/ContaoManager/PluginTest.php b/manager-bundle/tests/ContaoManager/PluginTest.php index 023c27fd27f..6911889dd51 100644 --- a/manager-bundle/tests/ContaoManager/PluginTest.php +++ b/manager-bundle/tests/ContaoManager/PluginTest.php @@ -570,6 +570,48 @@ public function getMailerParameters(): \Generator ]; } + public function testSetsTheSendmailCommand(): void + { + ini_set('sendmail_path', '/foobar/sendmail -t'); + + $container = $this->getContainer(); + + $extensionConfig = (new Plugin())->getExtensionConfig('swiftmailer', [], $container); + + $this->assertTrue(isset($extensionConfig[0]['command'])); + } + + public function testDoesNotSetTheSendmailCommandIfAlreadyDefined(): void + { + $container = $this->getContainer(); + + $extensionConfigs = [[ + 'command' => '/foobar/sendmail -t', + ]]; + + $expect = $extensionConfigs; + + $extensionConfig = (new Plugin())->getExtensionConfig('swiftmailer', $extensionConfigs, $container); + + $this->assertSame($expect, $extensionConfig); + + $extensionConfigs = [ + [ + 'mailers' => [ + 'default' => [ + 'command' => '/foobar/sendmail -t', + ], + ], + ], + ]; + + $expect = $extensionConfigs; + + $extensionConfig = (new Plugin())->getExtensionConfig('swiftmailer', $extensionConfigs, $container); + + $this->assertSame($expect, $extensionConfig); + } + public function testRetrievesTheConnectionParametersFromTheConfiguration(): void { $pluginLoader = $this->createMock(PluginLoader::class); From c6ca77d85b89aab2a4157fd350410f8129366e63 Mon Sep 17 00:00:00 2001 From: Fritz Michael Gschwantner Date: Fri, 4 Sep 2020 15:18:38 +0100 Subject: [PATCH 2/4] do not use ini_set --- manager-bundle/tests/ContaoManager/PluginTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/manager-bundle/tests/ContaoManager/PluginTest.php b/manager-bundle/tests/ContaoManager/PluginTest.php index 6911889dd51..c25ecf1496c 100644 --- a/manager-bundle/tests/ContaoManager/PluginTest.php +++ b/manager-bundle/tests/ContaoManager/PluginTest.php @@ -572,13 +572,11 @@ public function getMailerParameters(): \Generator public function testSetsTheSendmailCommand(): void { - ini_set('sendmail_path', '/foobar/sendmail -t'); - $container = $this->getContainer(); $extensionConfig = (new Plugin())->getExtensionConfig('swiftmailer', [], $container); - $this->assertTrue(isset($extensionConfig[0]['command'])); + $this->assertTrue(!ini_get('sendmail_path') || isset($extensionConfig[0]['command'])); } public function testDoesNotSetTheSendmailCommandIfAlreadyDefined(): void From 4aa8fceb0fa089d2e266631712b68c2c771a0303 Mon Sep 17 00:00:00 2001 From: Fritz Michael Gschwantner Date: Fri, 4 Sep 2020 15:25:09 +0100 Subject: [PATCH 3/4] drop support for old Swiftmailer version --- manager-bundle/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manager-bundle/composer.json b/manager-bundle/composer.json index d3055e7361b..496d3bb5377 100644 --- a/manager-bundle/composer.json +++ b/manager-bundle/composer.json @@ -50,7 +50,7 @@ "symfony/routing": "4.4.*", "symfony/security-bundle": "4.4.*", "symfony/stopwatch": "4.4.*", - "symfony/swiftmailer-bundle": "^2.6.2 || ^3.1.5", + "symfony/swiftmailer-bundle": "^3.1.5", "symfony/twig-bundle": "4.4.*", "symfony/web-profiler-bundle": "4.4.*", "symfony/yaml": "4.4.*", From e7f6d25d8564193749fdd5c107e6d7b69526aade Mon Sep 17 00:00:00 2001 From: Fritz Michael Gschwantner Date: Fri, 4 Sep 2020 15:30:13 +0100 Subject: [PATCH 4/4] increase version requirement for swiftmailer/swiftmailer-bundle --- manager-bundle/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manager-bundle/composer.json b/manager-bundle/composer.json index 496d3bb5377..57858a8d045 100644 --- a/manager-bundle/composer.json +++ b/manager-bundle/composer.json @@ -50,7 +50,7 @@ "symfony/routing": "4.4.*", "symfony/security-bundle": "4.4.*", "symfony/stopwatch": "4.4.*", - "symfony/swiftmailer-bundle": "^3.1.5", + "symfony/swiftmailer-bundle": "^3.2.8", "symfony/twig-bundle": "4.4.*", "symfony/web-profiler-bundle": "4.4.*", "symfony/yaml": "4.4.*",