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 3fe6fa08c..ae0d22f01 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -35,6 +35,7 @@ use Doctrine\Common\Persistence\ObjectManagerAware; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Proxy\Proxy; +use Doctrine\ORM\Event\CleanPostFlushEventArgs; use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\ORM\Event\PreUpdateEventArgs; use Doctrine\ORM\Event\PreFlushEventArgs; @@ -354,6 +355,7 @@ class UnitOfWork implements PropertyChangedListener $this->orphanRemovals)) { $this->dispatchOnFlushEvent(); $this->dispatchPostFlushEvent(); + $this->dispatchCleanPostFlushEvent(); return; // Nothing to do. } @@ -437,6 +439,8 @@ class UnitOfWork implements PropertyChangedListener $this->visitedCollections = $this->scheduledForSynchronization = $this->orphanRemovals = array(); + + $this->dispatchCleanPostFlushEvent(); } /** @@ -3326,6 +3330,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 *