From a29d07b00d791a8eed111e093af5d11541c4dc95 Mon Sep 17 00:00:00 2001 From: Ben Thomson Date: Thu, 25 Aug 2022 16:45:49 +0800 Subject: [PATCH 1/3] Reverse order in checking mail config styles This reverses the order for checking mail configs by searching for the new format first, then checking for the old format. Laravel checks old format first, then new format, which works fine for them, but doesn't work for us as we also populate settings via the Backend, which populates the settings in the new format. Fixes https://github.com/wintercms/winter/issues/626 --- src/Mail/MailManager.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Mail/MailManager.php b/src/Mail/MailManager.php index ade48d425..fde253981 100644 --- a/src/Mail/MailManager.php +++ b/src/Mail/MailManager.php @@ -7,6 +7,7 @@ * Overrides the Laravel MailManager * - Replaces the Laravel Mailer class with the Winter Mailer class * - Fires mailer.beforeRegister & mailer.register events + * - Uses another method to determine old vs. new mail configs */ class MailManager extends BaseMailManager { @@ -71,4 +72,30 @@ protected function resolve($name) return $mailer; } + + /** + * @inheritDoc + */ + protected function getConfig(string $name) + { + // Here we will check if the "mailers" key exists and if it does, we will use that to + // determine the applicable config. Laravel checks if the "drivers" key exists, and while + // that does work for Laravel, it doesn't work in Winter when someone uses the Backend to + // populate mail settings, as these mail settings are populated into the "mailers" key. + return $this->app['config']['mail.mailers'] + ? ($this->app['config']["mail.mailers.{$name}"] ?? $this->app['config']['mail']) + : $this->app['config']['mail']; + } + + /** + * @inheritDoc + */ + public function getDefaultDriver() + { + // We will do the reverse of what Laravel does and check for "default" first, which is + // populated by the Backend or the new "mail" config, before searching for the "driver" + // key that was present in older version of Winter. + return $this->app['config']['mail.default'] ?? $this->app['config']['mail.driver']; + } + } From cfd504685e11a6dff488faced90d1d053c8e7f51 Mon Sep 17 00:00:00 2001 From: Ben Thomson Date: Thu, 25 Aug 2022 16:49:31 +0800 Subject: [PATCH 2/3] Fix code smell --- src/Mail/MailManager.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Mail/MailManager.php b/src/Mail/MailManager.php index fde253981..18ac288d9 100644 --- a/src/Mail/MailManager.php +++ b/src/Mail/MailManager.php @@ -97,5 +97,4 @@ public function getDefaultDriver() // key that was present in older version of Winter. return $this->app['config']['mail.default'] ?? $this->app['config']['mail.driver']; } - } From faf4ea48cdf7e1c8694519f9d27cad40ce34a252 Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Mon, 17 Oct 2022 14:22:15 -0600 Subject: [PATCH 3/3] Update src/Mail/MailManager.php --- src/Mail/MailManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mail/MailManager.php b/src/Mail/MailManager.php index 18ac288d9..45ee036d9 100644 --- a/src/Mail/MailManager.php +++ b/src/Mail/MailManager.php @@ -94,7 +94,7 @@ public function getDefaultDriver() { // We will do the reverse of what Laravel does and check for "default" first, which is // populated by the Backend or the new "mail" config, before searching for the "driver" - // key that was present in older version of Winter. + // key that was present in older version of Winter (<1.2). return $this->app['config']['mail.default'] ?? $this->app['config']['mail.driver']; } }