-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
preFlush event and lifecycle callback #169
Conversation
*/ | ||
private $_em; | ||
|
||
//private $_entitiesToPersist = array(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this code still needed ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, missed that :-) Fixed!
What about XML and YML? |
@beberlei it should be evaluated in the same way: There's no explicit event check in the Xml and Yaml driver. If the event name exists inside the |
@@ -259,6 +259,41 @@ class UnitOfWork implements PropertyChangedListener | |||
*/ | |||
public function commit($entity = null) | |||
{ | |||
// Run preFlush lifecycle callback for new entities |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couldnt triggering these be done inside computeChangeSets, before every specific entity? That way we only need to loop once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in commit below ;-)
@everzet i think we dont need a lifecycle event for this. just an event for listeners. Why do you want this to be on the entities also? |
@beberlei i've created this PR because of some specific tasks, like file uploading/reuploading and i18n management. For now, we only have way to hook into persist (happens one time) and update (happens only if entity is changed) events. But in many cases, user will want to prepare his entity just before every flush. For example, we need to record translation changes before every flush, even if entity itself haven't updated or we need to update image value in entity, even if entity itself haven't updated. This hook will add missing part of control into the user-defined domain objects. And if you don't need it - then just don't use it. |
Merged |
For now, we have
@PrePersist
,@PreUpdate
and@PreRemove
callbacks. But it's not enough, cuz in some cases we need to run some entity method just before everyEntityManager#flush()
call (examples - translatable behavior and file uploading routines).I've added and tested new
@PreFlush
event, which occurs during the start of theEntityManager#flush()
, before any changeset gets calculated. This gives users ability to hook into flush process and prepare their entities to save even if they were not changed.