Review main Merged

77845[BUGFIX] Avoid repeated e-mail content generation in FluidEmail

Markus Klein CR +2 V +2 Hard +365 −24 updated 04/24/23, 18:18

Commit message

Body content generation may be triggered by calling some getter or
indirectly when the mail is sent (via `ensureValidity`).

This changes ensures that multiple tries to generate the body are only
executed if the state of the view has actually changed.

This enables extensions to manipulate the content of an e-mail via
events without getting their changes overridden again when the mail is
sent.

Review

  • Code review CR +2 Done
    • Stefan Bürk +2
    • Markus Klein +1
    • Christian Kuhn +1
  • Verified V +2 Done
    • Stefan Bürk +2
    • Christian Kuhn +1
    • core-ci +1 CI

Issues 1

Files 3

Review log 3038

Show 1113 earlier messages
  1. Markus Klein uploaded patch set 1 02/13/23, 20:07

  2. core-ci voted on patch set 1 V +1 02/13/23, 20:14 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37662

  3. Josef Glatz commented on patch set 1 02/13/23, 20:22

    FluidEmail.php:166

    could you describe the comment a little more factually? maybe a little bit more context?
  4. Markus Klein commented on patch set 2 V +1 02/13/23, 20:35

    Published edit on patch set 1.
  5. Markus Klein commented on patch set 2 02/13/23, 20:36

    FluidEmail.php:166 Reply

    Done
  6. Josef Glatz voted on patch set 2 CR +1 02/13/23, 20:37

  7. core-ci voted on patch set 2 V +1 02/13/23, 20:42 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/37663

  8. Josef Glatz voted on patch set 2 V +1 02/14/23, 12:11

  9. Thomas Hohn voted on patch set 2 CR +1 02/15/23, 19:45

  10. Stefan Bürk commented on patch set 2 CR -1 02/16/23, 19:44

    See comment. The solution breaks the enforcement on other methods.

    FluidEmail.php:169

    This is not a good solution. This will break the `$forceBodyGeneration` flag in `getTextBody()` and `getHtmlBdy()`, making it useless.
  11. Markus Klein commented on patch set 2 02/17/23, 07:26

    FluidEmail.php:169 Reply

    I don't understand why this should break it? Besides that the bool parameter is nowhere used in Core.
  12. Markus Klein commented on patch set 2 02/17/23, 07:27

    FluidEmail.php:169 Reply

    It's actually much worse that a method subject to check validity actually mutates state!
  13. Stefan Bürk commented on patch set 2 02/23/23, 12:11

    FluidEmail.php:169 Reply

    FluidMail is not just a core internal thing, and the force parameter is a public argument for a public method on a public api class. E.h. if variables are assigned, the body retrieved, the variable changed, and the body retrieved again it would not use the new variable due not rerendering the template. Even if $forceBodyGeneration = true is given to getTextBody() or getHtmlBody(). ```php $email = GeneralUtility::makeInstance(FluidEmail::class); // ... setting to, from, subject etc $email ->format(FORMAT_BOTH) ->assign('some-variable', 'Tomato and TypoScript'); $text1 = $email->getTextBody(); $email->assign('some-variable', 'Tomato and TypoScript CHANGED') $text2 = $email->getTextBody(true); // $text2 would be the same as $text1, not using the changed variable // because $forceBodyGeneration is now meaningless due the added // condition ``` Beside this, recenently saw people reusing the mail instance and just changing values. I know, bad habit but they do it. The introduced check / condition in `generateTemplatedBody()` has 2 flaws: * preventing regeneration template * not rendering a format if the other is set. ```php $email = GeneralUtility::makeInstance(FluidEmail::class); $email->format(FORMAT_BOTH); $text = $email->getTextBody(); $html = $email->getHtmlBody(); ``` The condition says, that if text OR html is set, no generation is done. Therefore the second format would not be rendered. The check should be extended at least, that it only checks if the value (parent get call) for the specified $format is not null and than return. Albit still leaving the $forceBodyGeneration broken. And the force argument should be handed to the generated method, to avoid that chack if argument is true.
  1. Markus Klein commented on patch set 2 02/23/23, 13:52

    FluidEmail.php:169 Reply

    Thanks for the analysis. Well, that's a chicken/egg now. Either double-Fluid-rendering is dead, or external content is dead. ;-) The true culprit is line 124, the side-effect of changing the message in an "assertion"-method.
  2. Markus Klein uploaded patch set 3 CR +1 V +1 03/24/23, 19:43

  3. Markus Klein commented on patch set 3 CR -1 03/24/23, 19:44

    on it

    FluidEmail.php:169 Reply

    Done
  4. Markus Klein voted on patch set 3 CR 0 03/24/23, 19:49

  5. Markus Klein uploaded patch set 4 03/24/23, 19:54

  6. core-ci voted on patch set 3 V -1 03/24/23, 20:05 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/39589

  7. Markus Klein uploaded patch set 5 03/24/23, 20:08

  8. core-ci voted on patch set 4 V -1 03/24/23, 20:16 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/39592

  9. core-ci voted on patch set 5 V +1 03/24/23, 20:16 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/39595

  10. Stefan Bürk voted on patch set 5 CR +1 03/24/23, 22:31

  11. Stefan Bürk commented on patch set 6 CR +1 V +1 03/24/23, 22:33

    Published edit on patch set 5.
  12. Stefan Bürk commented on patch set 6 CR -1 03/24/23, 22:36

    I try to add some tests for this ...
  13. core-ci voted on patch set 6 V +1 03/24/23, 22:43 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/39613

  14. Stefan Bürk commented on patch set 6 04/24/23, 03:22

    Tried to come up with some tests. It revealed, that this is not really working out. @Markus Klein Could we have a slack call the next days about this ?
  15. Stefan Bürk uploaded patch set 7 CR -1 V +1 04/24/23, 08:56

  16. Stefan Bürk commented on patch set 7 04/24/23, 08:57

    Reply

    Pushed tests with patchset 7 (should faild). Will discuss this with Markus, and push a change which will work along with these tests later.
  17. Stefan Bürk voted on patch set 7 CR -1 04/24/23, 08:57

  18. core-ci voted on patch set 7 V -1 04/24/23, 09:20 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/41129

  19. Stefan Bürk uploaded patch set 8 CR -1 V -1 04/24/23, 13:46

  20. core-ci voted on patch set 8 V +1 04/24/23, 13:54 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/41168

  21. Markus Klein voted on patch set 8 CR +1 04/24/23, 14:00

  22. Stefan Bürk voted on patch set 8 V +1 CR +1 04/24/23, 14:13

  23. Christian Kuhn voted on patch set 8 V +1 CR +1 04/24/23, 18:15

  24. Stefan Bürk voted on patch set 8 V +2 CR +2 04/24/23, 18:18

  25. Stefan Bürk merged patch set 9 04/24/23, 18:18