dev/core#2587 Ignore modified_date when checking for changes during mailing auto-save #20561
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Prevents double auto-save at each modification of a mailing in the mailing editor.
https://lab.civicrm.org/dev/core/-/issues/2587
Before
Whenever a mailing or A/B mailing is modified in the editor, the auto-save is triggered twice: once because the mailing was modified, once because after the first save the modified date of the local object does not match the one of the server response (because the server overwrote its value).
After
The modified date is ignored in the comparison for the auto-save, so that the second unnecessary save does not happen.
Technical Details
The suggestion of the issue on how to implement the fix does not work because the model is not a single object, but a list of objects (mailing(s), optional ab mailing, attachments). The autoSave controller is generic and is agnostic of the structure of the model, so finding and ignoring the modified date could not happen there. This is why instead I chose to edit the model before giving it to the autoSave controller. As far as I can see this affects only the autoSave.
Comments
When testing the fix, you may notice that the autoSave still happens twice, but only for the first time it is triggered. I found out this is another unrelated bug, due to the schedule date being set to empty string or null depending on whether it comes from initialisation or server response. I didn't chase this bug further.