-
-
Notifications
You must be signed in to change notification settings - Fork 828
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
CiviMail - Restore support for preview of "mailing"/"action" tokens via TokenProcessor/Flexmailer #14156
Conversation
…essor/Flexmailer Overview -------- When using `TokenProcessor` to generate a mailing (e.g. as with Flexmailer/Mosaico), the action-tokens (e.g. `{action.optOutUrl}`) are generated via `CRM_Mailing_ActionTokens`. To properly generate them, `CRM_Mailing_ActionTokens` relies on certain information (e.g. mailing/job ID). However, that information is no longer available when performing a "Preview" -- leading to misbehavior in previews. This patch allows Flexmailer to restore parity for previewing those tokens. Before (Pre-5.6) ---------------- * When a user begins composing a mailing, CiviMail creates a draft mailing with a concrete ID (e.g. `mailing civicrm#123`). * To preview the mailing, the UI calls `Mailing.preview` API with the ID of the mailing. * Flexmailer/Mosaico generates the preview by calling `TokenProcessor` and therefore `CRM_Mailing_ActionTokens`. * `CRM_Mailing_ActionTokens` has strictness checks. These pass because the ID is available. Before (5.6-5.12) ---------------- As a performance enhancement, CiviCRM 5.6 (PR civicrm#12509; [dev/mail#20](https://lab.civicrm.org/dev/mail/issues/20)) revised the signature for `Mailing.preview` API to allow previews *without* having a specific mailing record/job/ID. Consequently: * When a user begins composing a mailing, CiviMail creates a draft mailing with a concrete ID (e.g. `mailing civicrm#123`). * To preview the mailing, the UI calls `Mailing.preview` API ~~with~~ **without** the ID of the mailing. * Flexmailer/Mosaico generates the preview by calling `TokenProcessor` and therefore `CRM_Mailing_ActionTokens`. * `CRM_Mailing_ActionTokens` has strictness checks. These ~~pass~~ **fail** because the ID is ~~available~~ **unavailable**. After ---------------- * When a user begins composing a mailing, CiviMail creates a draft mailing with a concrete ID (e.g. `mailing civicrm#123`). * To preview the mailing, the UI calls `Mailing.preview` API ~~with~~ **without** the ID of the mailing. * Flexmailer/Mosaico generates the preview by calling `TokenProcessor` and therefore `CRM_Mailing_ActionTokens`. * `CRM_Mailing_ActionTokens` has ~~strictness~~ **less strict** checks. These **pass** because the `context[schema]` hints that a mailing ID *will be available* when needed.
…cessor/Flexmailer See preceding commit for general description - this simply applies the same concept for another set of tokens.
(Standard links)
|
@seamuslee001 @colemanw @mattwire @monishdeb @lcdservices do any of you feel placed to review this? some of you were involved in the pr that causes this so might have some background |
Aside: @seamuslee001 @eileenmcnaughton Given the age of the underlying regression, it's tempting to put this |
Code looks fine to me and I am a +1 for this being in the RC |
The preceding commits revised the behavior of `{mailing.*}` and `{action.*}` when previewed via `TokenProcessor` (so that they match the preview logic in other cases). This simply changes the spec to match.
The code look sensible to me, I think we should merge this into the RC. As we have seen we have tests already in this area and the tests are being altered sensibly tbh. |
Overview
When using
TokenProcessor
to generate a mailing (e.g. as with Flexmailer/Mosaico), the mailing/action-tokens (e.g.{mailing.subject}
and{action.optOutUrl}
) are generated viaCRM_Mailing_Tokens
andCRM_Mailing_ActionTokens
. To properly generate them,CRM_Mailing_Tokens
andCRM_Mailing_ActionTokens
check the mailing/job ID. However, that information is no longer available when performing a "Preview" -- leading to misbehavior in previews. In combination with civicrm/org.civicrm.flexmailer#38, this restores parity for token/preview support.Before (Pre-5.6; OK)
mailing #123
).Mailing.preview
API with the ID of the mailing.TokenProcessor
and thereforeCRM_Mailing_ActionTokens
.CRM_Mailing_ActionTokens
has strictness checks. These pass because the ID is available.Before (5.6-5.12; Not OK)
As a performance enhancement, CiviCRM 5.6 (PR #12509; dev/mail#20) revised the signature for
Mailing.preview
API to allow previews without having a specific mailing record/job/ID. Consequently:mailing #123
).Mailing.preview
APIwithwithout the ID of the mailing.TokenProcessor
and thereforeCRM_Mailing_ActionTokens
.CRM_Mailing_ActionTokens
has strictness checks. Thesepassfail because the ID isavailableunavailable.After (OK)
mailing #123
).Mailing.preview
APIwithwithout the ID of the mailing.TokenProcessor
and thereforeCRM_Mailing_ActionTokens
.CRM_Mailing_ActionTokens
hasstrictnessless strict checks. These pass because thecontext[schema]
hints that a mailing ID will be available when it's really needed.Comments
The change in contract for
Mailing.preview
API has produced multiple overlapping issues -- including this issue incivicrm-core
and some other issues inflexmailer
. Theflexmailer
issues generally involve getting the wrong information about a previewed mailing because theid
is unavailable. Unfortunately, because of the overlapping issues, it can be hard to produce a clear/singular symptom. (Ex: The symptoms change significantly depending on thetemplate_type
of the first mailing in the DB and/or depending on whether you enable the hidden settingexperimentalFlexMailerEngine
.)With regard to QA for this PR, some important mitigating circumstances to note:
civicrm-core
) doesn't useTokenProcessor
orCRM_*_Tokens
. That change was done as "leap by extension" (flexmailer
).civicrm-core
does useTokenProcessor
for scheduled reminders - but they don't involve mailings.CiviCRM-Ext-Matrix
once it's merged. (However, that PR currently fails because it depends on having this change!)