-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(REF) Move CIVICRM_MAIL_LOG logic from patch-files to wrapper-class #16497
Conversation
Overview -------- This aims to improve maintainablity and deployment workflows by reduing the scope of the needed files. It is an alternative approach for civicrm#16481. Before ------ `civicrm-core` included patch files for `pear/mail`. These files modified the behavior of `Mail_sendmail`, `Mail_smtp`, and `Mail_mail` to ensure that the `send()` function would abide by the `CIVICRM_MAIL_LOG` constant. After ----- `civicrm-core` includes a wrapper class `LoggingMailer`. It takes an instance of `Mail_sendmail`, `Mail_smtp`, or `Mail_mail` and mixes-in the `CIVICRM_MAIL_LOG` logic. Technical Details ----------------- There is a `hook_civicrm_alterMailer`, for which consumers could potentially see a change in behavior (because the concrete-class of `$mailer` may change and support different properties). Mitigating factors: * There is only one public method in the `Mail` contract: `send()`. * The only example of `alterMailer` in the documentation suggests that you wholly replace the object with your own implementation. This was the original purpose. If you use it this way, then it doesn't matter what's happening inside the old object. https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterMailer/ * In public `universe`, there is only one extension (Cividesk's Sparkpost) which uses this hook. And it does swap in that expected way. * Just in case... the `LoggingMailer` passes-through all calls to read/write properties. You can see this in action in a specific configuration, e.g. ``` ## Before patch $ cv ev '$m=Civi::service("pear_mail"); return [get_class($m), $m->host];' [ "Mail_smtp", "127.0.0.1" ] ## After patch $ cv ev '$m=Civi::service("pear_mail"); return [get_class($m), $m->host];' [ "CRM_Utils_Mail_LoggingMailer", "127.0.0.1" ] ```
(Standard links)
|
@totten this test failure |
jenkins, test this please Yeah, at a first glance, it does seem plausible. I tried running the test locally (both in isolation and in the full suite), and it didn't reproduce. It could also be coincidence in a test that's a little time-sensitive. Consider Fingers crossed 🤞 for another run to give better result. |
Test fail is unrelated |
@totten I did an r-run of this by clearing out my local vendor folder and reinstalling packages and clearing cache then submitting the SMTP settings to send a test email. I had to make one additional patch to make it work. However once done it seemed to work correctly diff --git a/CRM/Admin/Form/Setting/Smtp.php b/CRM/Admin/Form/Setting/Smtp.php
index 87d30761cf..a3590b3ca2 100644
--- a/CRM/Admin/Form/Setting/Smtp.php
+++ b/CRM/Admin/Form/Setting/Smtp.php
@@ -165,7 +165,7 @@ class CRM_Admin_Form_Setting_Smtp extends CRM_Admin_Form_Setting {
'Subject' => $subject,
];
- $mailer = Mail::factory($mailerName, $params);
+ $mailer = CRM_Utils_Mail::_createMailer($mailerName, $params);
$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
$result = $mailer->send($toEmail, $headers, $message); |
@totten i think we also will need to modify this https://github.com/civicrm/civicrm-core/pull/16497/files#diff-6c43a3f8cc4e99bd04af92421c03179eR275 |
When civicrm-core used patches to change the behavior of `Mail_mail` (etal), this was fine. The preceding commit removes the patches and uses a wrapper instead - so it's more important to get the same mailer as the regular CRM_Utils_Mail logic.
Good points @seamuslee001 ! Some follow-ups:
|
Changes look good to me adding merge on pass |
test this please |
…d Logger 1. Captures more context (i.e. the original driver and params) 2. Changes various property names to avoid potential for conflict with delegated properties 3. Adds `addFilter($id, $func)` so that one can move more filters in here 4. Consolidates the various references ot CIVICRM_MAIL_LOG* into one file.
1a53571
to
e4c7508
Compare
There were a large number of failures like this...
... because the It should be empty ( |
Overview
This aims to improve maintainablity and deployment workflows by reduing the
scope of the needed patch-files.
It is an alternative approach for #16481.
Before
civicrm-core
included patch files forpear/mail
. These files modifiedthe behavior of
Mail_sendmail
,Mail_smtp
, andMail_mail
to ensure thatthe
send()
function would abide by theCIVICRM_MAIL_LOG
constant.After
civicrm-core
includes a wrapper classLoggingMailer
. It takes aninstance of
Mail_sendmail
,Mail_smtp
, orMail_mail
and mixes-in theCIVICRM_MAIL_LOG
logic. The resulting object is still an instance ofMail
.Technical Details
There is a
hook_civicrm_alterMailer
, for which consumers could potentiallysee a change in behavior (because the concrete-class of
$mailer
maychange and support different properties). Mitigating factors:
Mail
contract:send()
.alterMailer
in the documentation suggeststhat you wholly replace the object with your own implementation.
This was the original purpose. If you use it this way, then it doesn't
matter what's happening inside the old object.
https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterMailer/
universe
, there is only one extension (Cividesk's Sparkpost)which uses this hook. And it does swap in that expected way.
LoggingMailer
passes-through all calls to read/write properties.You can see this in action in a specific configuration, e.g.
Comments
Ping @seamuslee001