1
0
mirror of synced 2025-01-19 06:51:40 +03:00

Merge branch 'DDC-2173'

This commit is contained in:
Benjamin Eberlei 2013-01-06 19:12:02 +01:00
commit c20cfed6ae
3 changed files with 61 additions and 8 deletions

View File

@ -1,3 +1,11 @@
# Upgrade to 2.4
## OnFlush and PreFlush event always called
Before 2.4 the preFlush and onFlush events were only called when there were
actually entities that changed. Now these events are called no matter if there
are entities in the UoW or changes are found.
# Upgrade to 2.3
## EntityManager#find() not calls EntityRepository#find() anymore

View File

@ -287,6 +287,9 @@ class UnitOfWork implements PropertyChangedListener
$this->collectionUpdates ||
$this->collectionDeletions ||
$this->orphanRemovals)) {
$this->dispatchOnFlushEvent();
$this->dispatchPostFlushEvent();
return; // Nothing to do.
}
@ -296,10 +299,7 @@ class UnitOfWork implements PropertyChangedListener
}
}
// Raise onFlush
if ($this->evm->hasListeners(Events::onFlush)) {
$this->evm->dispatchEvent(Events::onFlush, new Event\OnFlushEventArgs($this->em));
}
$this->dispatchOnFlushEvent();
// Now we need a commit order to maintain referential integrity
$commitOrder = $this->getCommitOrder();
@ -354,10 +354,7 @@ class UnitOfWork implements PropertyChangedListener
$coll->takeSnapshot();
}
// Raise postFlush
if ($this->evm->hasListeners(Events::postFlush)) {
$this->evm->dispatchEvent(Events::postFlush, new Event\PostFlushEventArgs($this->em));
}
$this->dispatchPostFlushEvent();
// Clear up
$this->entityInsertions =
@ -3153,4 +3150,18 @@ class UnitOfWork implements PropertyChangedListener
return isset($this->readOnlyObjects[spl_object_hash($object)]);
}
private function dispatchOnFlushEvent()
{
if ($this->evm->hasListeners(Events::onFlush)) {
$this->evm->dispatchEvent(Events::onFlush, new Event\OnFlushEventArgs($this->em));
}
}
private function dispatchPostFlushEvent()
{
if ($this->evm->hasListeners(Events::postFlush)) {
$this->evm->dispatchEvent(Events::postFlush, new Event\PostFlushEventArgs($this->em));
}
}
}

View File

@ -48,6 +48,26 @@ class FlushEventTest extends \Doctrine\Tests\OrmFunctionalTestCase
//echo "SECOND FLUSH";
//$this->_em->flush();
}
/**
* @group DDC-2173
*/
public function testPreAndOnFlushCalledAlways()
{
$listener = new OnFlushCalledListener();
$this->_em->getEventManager()->addEventListener(Events::onFlush, $listener);
$this->_em->getEventManager()->addEventListener(Events::preFlush, $listener);
$this->_em->flush();
$this->assertEquals(1, $listener->preFlush);
$this->assertEquals(1, $listener->onFlush);
$this->_em->flush();
$this->assertEquals(2, $listener->preFlush);
$this->assertEquals(2, $listener->onFlush);
}
}
class OnFlushListener
@ -91,4 +111,18 @@ class OnFlushListener
}
}
class OnFlushCalledListener
{
public $preFlush = 0;
public $onFlush = 0;
public function preFlush($args)
{
$this->preFlush++;
}
public function onFlush($args)
{
$this->onFlush++;
}
}