diff --git a/lib/Doctrine/ORM/Event/CleanPostFlushEventArgs.php b/lib/Doctrine/ORM/Event/CleanPostFlushEventArgs.php new file mode 100644 index 000000000..bccac5320 --- /dev/null +++ b/lib/Doctrine/ORM/Event/CleanPostFlushEventArgs.php @@ -0,0 +1,34 @@ +em = $em; + } + + /** + * @return EntityManagerInterface + */ + public function getEntityManager(): EntityManagerInterface + { + return $this->em; + } +} diff --git a/lib/Doctrine/ORM/Events.php b/lib/Doctrine/ORM/Events.php index e16b47a42..d70ee9769 100644 --- a/lib/Doctrine/ORM/Events.php +++ b/lib/Doctrine/ORM/Events.php @@ -157,6 +157,16 @@ final class Events */ const postFlush = 'postFlush'; + /** + * The cleanPostFlush event occurs when the EntityManager#flush() operation is invoked and + * after all actual database operations are executed successfully. + * All information about performed database operations has been cleared before raising cleanPostFlush event. + * This means that flush calls can be performed in cleanPostFlush event. + * + * @var string + */ + const cleanPostFlush = 'cleanPostFlush'; + /** * The onClear event occurs when the EntityManager#clear() operation is invoked, * after all references to entities have been removed from the unit of work. diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index c79afd084..41233413d 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -27,6 +27,7 @@ use Doctrine\Common\Persistence\ObjectManagerAware; use Doctrine\Common\PropertyChangedListener; use Doctrine\DBAL\LockMode; use Doctrine\ORM\Cache\Persister\CachedPersister; +use Doctrine\ORM\Event\CleanPostFlushEventArgs; use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\ORM\Event\ListenersInvoker; use Doctrine\ORM\Event\OnFlushEventArgs; @@ -355,6 +356,7 @@ class UnitOfWork implements PropertyChangedListener $this->orphanRemovals)) { $this->dispatchOnFlushEvent(); $this->dispatchPostFlushEvent(); + $this->dispatchCleanPostFlushEvent(); return; // Nothing to do. } @@ -430,6 +432,8 @@ class UnitOfWork implements PropertyChangedListener $this->dispatchPostFlushEvent(); $this->postCommitCleanup($entity); + + $this->dispatchCleanPostFlushEvent(); } /** @@ -3396,6 +3400,13 @@ class UnitOfWork implements PropertyChangedListener } } + private function dispatchCleanPostFlushEvent() + { + if ($this->evm->hasListeners(Events::cleanPostFlush)) { + $this->evm->dispatchEvent(Events::cleanPostFlush, new CleanPostFlushEventArgs($this->em)); + } + } + /** * Verifies if two given entities actually are the same based on identifier comparison *