Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
DDC-1599: OnFlush event in transaction #2236
Jira issue originally created by user gediminasm:
Is there any particular reason why onFlush event is not triggered when the transaction is allready open? https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/UnitOfWork.php#L290 It would help a lot developing listeners since this event is the mostly used one and since theres preFlush now it seems a logical solution if onFlush would be a start of transaction in general
Comment created by gediminasm:
Well, user can start transaction anytime, but the fact is that if we think ORM we do not know nothing about the database. we just persist and flush objects.
Yes I think these would be very useful, from how I see it, if you use event listeners, is:
loadClassMetadata: you can apply extra mapping
onFlush: you can modify entity changesets, or persist recalculate new ones, without triggering the database, since it is not used to begin the database modifications yet.
onBeginTransaction: could use the database modifications keeping in sync the entity changesets. the thing about this event is that usually in behavioral way atomic updates are required. for example nestedset tree sync lft rgt columns, sortable sync the sort index, materialized path, all these requires atomic updates, and the best place is the start of transaction.
onCommit: could be useful to execute right before commit, finalizing database modifications could be done.
onRollback: this one is really something, since if you go far, there might be something like files uploaded during the entity processing, and you may want to remove them if transaction fails.
Comment created by @guilhermeblanco:
This situation was barely documented here: http://www.doctrine-project.org/jira/browse/[DDC-1443](http://www.doctrine-project.org/jira/browse/DDC-1443)
We need a better Transaction API that completely fixes the computation of changesets and also allow more fine grained control over Entities and their corresponding information.
I'd postpone this one until 3.0.