mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
[PR #1022] [CLOSED] Added EndFlush event #9042
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/doctrine/orm/pull/1022
Author: @dantleech
Created: 4/29/2014
Status: ❌ Closed
Base:
master← Head:end_flush📝 Commits (1)
e85c50dAdded EndFlush event📊 Changes
5 files changed (+113 additions, -4 deletions)
View changed files
📝
docs/en/reference/events.rst(+31 -3)➕
lib/Doctrine/ORM/Event/EndFlushEventArgs.php(+31 -0)📝
lib/Doctrine/ORM/Events.php(+8 -0)📝
lib/Doctrine/ORM/UnitOfWork.php(+19 -0)📝
tests/Doctrine/Tests/ORM/Functional/FlushEventTest.php(+24 -1)📄 Description
This was mentioned on Twitter, this is just a POC to further the discussion.
Updated 10-05-2014
The flush terminate event would be fired after the flush has finished only when there are pending changes.
My primary use case is to enable enitities to be persisted recursively after the initial flush.
The existing
endFlushevent is fired before the UOW is cleaned up, i.e. whilst the UOW is still dirty.Use cases
Example problem
For example, we flush an
Articleentity.Routeentity automaticallyfor the
Articleentity.Versionentity for eachRoute.In the first listener would listen to the
onFlushevent, check the changesets for anyArticleenitities, create a new
Routeentity and recompute the changeset. The newRouteentity wouldthen be committed in one flush.
There is however no sensible way to implement the second listener - if we were to
implement it in
onFlushwe would have to be sure that the listener was called after the first listener.This "order of precendence" problem doesn't scale.
With the
terminateFlushevent.Articleentity would be persistedflush()RouteEventSubscribersubscriber listens to theonFlushevent and tracks anyRouteobjects which are due to be persisted.flushTerminateevent would be firedRouteEventSubscriberchecks to see if anyRouteobjects have been persisted, if so it creates a newRouteobject, peristsit, and calls flush again.
The same process now take place with a
VersionEventSubscriber.So in summary, when an Article is comitted, 3 flushes take place and three enitities are persisted.
Transactions
I think that any additional flushes should not be part of the same transaction.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.