Mailtrain-org / mailtrain

Self hosted newsletter app
GNU General Public License v3.0
5.53k stars 692 forks source link

[V2] Template is not updated when parent Mosaico template #605

Closed goooseman closed 5 years ago

goooseman commented 5 years ago

Steps to reproduce

  1. Create a MJML Mosaico template (default can be taken)
  2. Create a MJML template using Mosaico template from step 1
  3. Change MJML Mosaico template (eg. change 1 letter in the header)
  4. Use transactional mail API to send email

Expected

The mail should include changes from step 3

Actual

Mail is delivered with the original template before the change

I can try to fix the problem and create a PR, but I need a help where to look at.

goooseman commented 5 years ago

If it is send through Campaigns the problem exists too.

So the template is not updated from mosaico template it was created from until opened and saved.

bures commented 5 years ago

Let's say it's not a bug, but a feature. You have to open the template and save it again. The problem is that Mosaico has to regenerate the template based on the Mosaico template. This cannot be easily done on the server since Mosaico is client based. Also, it's better that you check the template to see what the changes in the Mosaico template did to it before you send it out.

goooseman commented 5 years ago

It is a problem for us, because we are doing 16 different templates from one Mosaico template. So I have two questions:

1) Maybe I can make following. If special env var is passed (UPDATE_MOSAICO) after the parent mosaico template is changed, server launches puppeter (headless Chrome) (or phantomjs, as it is already in the project), authenticates using cookie with a session of user, opens every template, which was created from the changed one, and saves it. 2) Maybe there is another way (not mosaico template) to make one email layout (header, footer and etc.), which will be used by different MJML templates?

Thank you in advance.

bures commented 5 years ago

I understand the point. Well, it's a bit more difficult because if you launch a puppeteer after Mosaico template change to update all the templates based on the Mosaico template, it means that those templates will be for a certain while in an undefined state (until they are regenerated). To be completely correct, we would have to report this undefined state in the UI and possibly block sending out campaigns as long as the template is in the undefined state, etc., etc.

What might work as less systematic solution, but would be enough for you, is to create an external command-line tool that does the update (in whatever way). You can invoke the tool manually after you change the mosaico template. You could even hook a execution of the tool to saving the mosaico template.

I would be happy to accept PR for the standalone command-line tool. I would not include calling the tool from save of the mosaico template in the Mailtrain git. However this would be just one change line in your code (thus easy to maintain even when updates to Mailtrain are coming).

Thanks.