From 9c4c06c42219866b2bb3d99785b2abb2bb7f4952 Mon Sep 17 00:00:00 2001 From: everzet Date: Thu, 3 Nov 2011 16:24:47 +0200 Subject: [PATCH] optimized PreFlush (moved into computeChangeSet function) --- lib/Doctrine/ORM/UnitOfWork.php | 35 +++++---------------------------- 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index d8b640c47..ea7138c98 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -259,36 +259,6 @@ class UnitOfWork implements PropertyChangedListener */ public function commit($entity = null) { - // Run preFlush lifecycle callback for new entities - foreach ($this->entityInsertions as $classEntity) { - $class = $this->em->getClassMetadata(get_class($classEntity)); - - // Skip class if instances are read-only - if ($class->isReadOnly) { - continue; - } - - if (isset($class->lifecycleCallbacks[Events::preFlush])) { - $class->invokeLifecycleCallbacks(Events::preFlush, $classEntity); - } - } - - // Run preFlush lifecycle callback for persisted entities - foreach ($this->identityMap as $className => $classEntities) { - $class = $this->em->getClassMetadata($className); - - // Skip class if instances are read-only - if ($class->isReadOnly) { - continue; - } - - if (isset($class->lifecycleCallbacks[Events::preFlush])) { - foreach ($classEntities as $classEntity) { - $class->invokeLifecycleCallbacks(Events::preFlush, $classEntity); - } - } - } - // Raise preFlush if ($this->evm->hasListeners(Events::preFlush)) { $this->evm->dispatchEvent(Events::preFlush, new Event\PreFlushEventArgs($this->em)); @@ -516,6 +486,11 @@ class UnitOfWork implements PropertyChangedListener return; } + // Fire PreFlush lifecycle callbacks + if (isset($class->lifecycleCallbacks[Events::preFlush])) { + $class->invokeLifecycleCallbacks(Events::preFlush, $entity); + } + $actualData = array(); foreach ($class->reflFields as $name => $refProp) { $value = $refProp->getValue($entity);