Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

(dev/mail#20) Mailing.preview - Fix regression circa Civi 5.6.x #38

Merged
merged 2 commits into from
Apr 30, 2019

Conversation

totten
Copy link
Member

@totten totten commented Apr 26, 2019

Flexmailer overrides the Mailing.preview API. In
civicrm/civicrm-core#12509 (5.6), it became possible
to call Mailing.preview without an id for the mailing.

This update Flexmailer Mailing.preview to also work without an ID.

It resolves a symptom in which clicking "Preview as (HTML/Text)" seems to work - but renders mailing#1 instead of rendering the actual draft mailing.

@civibot civibot bot added the master label Apr 26, 2019
@totten totten changed the title (dev/mail#20) Mailing.preview - Fix regression circa Civi 5.6.x (WIP) (dev/mail#20) Mailing.preview - Fix regression circa Civi 5.6.x Apr 27, 2019
totten added a commit to totten/civicrm-core that referenced this pull request Apr 29, 2019
…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.

Note: This is a pre-requisite for the full fix civicrm/org.civicrm.flexmailer#38

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.
totten added a commit to totten/civicrm-core that referenced this pull request Apr 29, 2019
…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.

Note: This is a pre-requisite for the full fix civicrm/org.civicrm.flexmailer#38

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.
…x (dev/mail#20)

Flexmailer overrides the `Mailing.preview` API.  In
civicrm/civicrm-core#12509 (5.6), it became possible
to call `Mailing.preview` without an `id` for the mailing.

This update Flexmailer `Mailing.preview` to also work without an ID,
and it expands unit-test coverage to ensure correct operation with
or without an ID.
@totten totten changed the title (WIP) (dev/mail#20) Mailing.preview - Fix regression circa Civi 5.6.x (dev/mail#20) Mailing.preview - Fix regression circa Civi 5.6.x Apr 30, 2019
@totten
Copy link
Member Author

totten commented Apr 30, 2019

Note: The expanded test-coverage correctly reports a failure - and it won't be fully resolved until civicrm/civicrm-core#14156 is merged. However, if I run the tests locally and include that patch, then they pass.

@seamuslee001
Copy link
Contributor

/test

@seamuslee001
Copy link
Contributor

/test

1 similar comment
@totten
Copy link
Member Author

totten commented Apr 30, 2019

/test

@totten totten merged commit d954ffd into civicrm:master Apr 30, 2019
@totten totten deleted the master-preview-512 branch April 30, 2019 17:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants