Improve: allow PreSaveEvent listeners to skip default object persistence#607
Open
ellenico77 wants to merge 1 commit into
Open
Improve: allow PreSaveEvent listeners to skip default object persistence#607ellenico77 wants to merge 1 commit into
ellenico77 wants to merge 1 commit into
Conversation
Add a skip-save flag to PreSaveEvent so listeners can decide programmatically whether an imported row should be persisted. ImportProcessingService now checks this flag after dispatching PreSaveEvent and returns early when save is skipped. Default behavior remains unchanged unless explicitly requested by a listener.
|
Author
|
Hi @fashxp, could you give me your opinion on the event extension proposal? It would be very helpful to me. If you think it's a good idea, I can reduce the cognitive complexity flagged by Sonar by moving the "if" and the two lines of code above into a new method. However, I think it’s outside of my responsibility, don’t I? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.




Summary
This PR introduces a small improvement to the Data Importer flow:
listeners of
PreSaveEventcan now programmatically decide whether the current imported object should be persisted or not.Motivation
In some import scenarios, a listener may fully handle a row (e.g. custom processing, aggregation, side effects) and therefore the default save operation should be skipped.
Before this change,
PreSaveEventlisteners could mutate data but could not explicitly prevent persistence.What changed
PreSaveEventto mark save as skippable.shouldSkipSave()/setSkipSave(bool $skipSave)).PreSaveEventand return early when save should be skipped.Result
This enables extension points where listeners can:
Backward compatibility
false, so existing imports continue to save as before.Branch compatibility
This improvement proposal is also applicable to the
2.4branch.