[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:
parent
3783ca6b43
commit
18d4a2f970
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user