1
0
mirror of synced 2025-01-18 06:21:40 +03:00

[DDC-1775] Fix NotifyPropertyChanged Listener being attached in addIdentityMap(), which is too late for certain use-cases in the persist lifecycle.

This commit is contained in:
Benjamin Eberlei 2012-07-07 17:47:29 +02:00
parent 3783ca6b43
commit 18d4a2f970
2 changed files with 26 additions and 8 deletions

View File

@ -1124,6 +1124,10 @@ class UnitOfWork implements PropertyChangedListener
if (isset($this->entityIdentifiers[$oid])) {
$this->addToIdentityMap($entity);
}
if ($entity instanceof NotifyPropertyChanged) {
$entity->addPropertyChangedListener($this);
}
}
/**
@ -1302,10 +1306,6 @@ class UnitOfWork implements PropertyChangedListener
$this->identityMap[$className][$idHash] = $entity;
if ($entity instanceof NotifyPropertyChanged) {
$entity->addPropertyChangedListener($this);
}
return true;
}
@ -2369,6 +2369,7 @@ class UnitOfWork implements PropertyChangedListener
$this->entityIdentifiers[$oid] = $id;
$this->entityStates[$oid] = self::STATE_MANAGED;
$this->originalEntityData[$oid] = $data;
$this->identityMap[$class->rootEntityName][$idHash] = $entity;
if ($entity instanceof NotifyPropertyChanged) {
@ -2800,6 +2801,10 @@ class UnitOfWork implements PropertyChangedListener
$this->originalEntityData[$oid] = $data;
$this->addToIdentityMap($entity);
if ($entity instanceof NotifyPropertyChanged) {
$entity->addPropertyChangedListener($this);
}
}
/**

View File

@ -40,9 +40,16 @@ class NotifyPolicyTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->persist($user);
$this->_em->persist($group);
$this->assertEquals(1, count($user->listeners));
$this->assertEquals(1, count($group->listeners));
$this->_em->flush();
$this->_em->clear();
$this->assertEquals(1, count($user->listeners));
$this->assertEquals(1, count($group->listeners));
$userId = $user->getId();
$groupId = $group->getId();
unset($user, $group);
@ -52,6 +59,9 @@ class NotifyPolicyTest extends \Doctrine\Tests\OrmFunctionalTestCase
$group = $this->_em->find(__NAMESPACE__.'\NotifyGroup', $groupId);
$this->assertEquals(1, $group->getUsers()->count());
$this->assertEquals(1, count($user->listeners));
$this->assertEquals(1, count($group->listeners));
$group2 = new NotifyGroup();
$group2->setName('nerds');
$this->_em->persist($group2);
@ -63,6 +73,9 @@ class NotifyPolicyTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->flush();
$this->_em->clear();
$this->assertEquals(1, count($user->listeners));
$this->assertEquals(1, count($group->listeners));
$group2Id = $group2->getId();
unset($group2, $user);
@ -77,7 +90,7 @@ class NotifyPolicyTest extends \Doctrine\Tests\OrmFunctionalTestCase
}
class NotifyBaseEntity implements NotifyPropertyChanged {
private $listeners = array();
public $listeners = array();
public function addPropertyChangedListener(PropertyChangedListener $listener) {
$this->listeners[] = $listener;