DDC-1599: OnFlush event in transaction #2007

Closed
opened 2026-01-22 13:37:24 +01:00 by admin · 6 comments
Owner

Originally created by @doctrinebot on GitHub (Jan 14, 2012).

Originally assigned to: @beberlei on GitHub.

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

Originally created by @doctrinebot on GitHub (Jan 14, 2012). Originally assigned to: @beberlei on GitHub. 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
admin added the Improvement label 2026-01-22 13:37:24 +01:00
admin closed this issue 2026-01-22 13:37:25 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jan 14, 2012):

Comment created by @beberlei:

onFluish is not the start of a transaction. It has nothing to do with this.

@doctrinebot commented on GitHub (Jan 14, 2012): Comment created by @beberlei: onFluish is not the start of a transaction. It has nothing to do with this.
Author
Owner

@doctrinebot commented on GitHub (Mar 31, 2012):

Comment created by @ocramius:

Is a third event needed? Or is this to be marked as "won't fix"?

@doctrinebot commented on GitHub (Mar 31, 2012): Comment created by @ocramius: Is a third event needed? Or is this to be marked as "won't fix"?
Author
Owner

@doctrinebot commented on GitHub (Mar 31, 2012):

Comment created by @beberlei:

Maybe onBeginTransaction, onCommit and onRollback.

However since you can start transactions manually using $em->beginTransaction(), the Flush events are somehwat independent of transactions anyways.

@doctrinebot commented on GitHub (Mar 31, 2012): Comment created by @beberlei: Maybe onBeginTransaction, onCommit and onRollback. However since you can start transactions manually using $em->beginTransaction(), the Flush events are somehwat independent of transactions anyways.
Author
Owner

@doctrinebot commented on GitHub (Mar 31, 2012):

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.

@doctrinebot commented on GitHub (Mar 31, 2012): 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.
Author
Owner

@doctrinebot commented on GitHub (May 21, 2012):

Comment created by @guilhermeblanco:

This situation was barely documented here: 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.

@doctrinebot commented on GitHub (May 21, 2012): 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.
Author
Owner

@guilhermeblanco commented on GitHub (Jan 3, 2017):

Any hook that modifies in-flight changeset should be done by a compute changeset event independently of transactional.
This is already planned as part of the ChangeSet calculation support.
Closing this one.

@guilhermeblanco commented on GitHub (Jan 3, 2017): Any hook that modifies in-flight changeset should be done by a compute changeset event independently of transactional. This is already planned as part of the ChangeSet calculation support. Closing this one.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2007