1
0
mirror of synced 2025-02-02 05:21:44 +03:00

Merge pull request #589 from Ocramius/hotfix/DDC-2230

Hotfix for DDC-2230
This commit is contained in:
Guilherme Blanco 2013-02-25 21:59:04 -08:00
commit d5dd7d6f8a
3 changed files with 115 additions and 3 deletions

View File

@ -2659,7 +2659,10 @@ class UnitOfWork implements PropertyChangedListener
$this->entityIdentifiers[$newValueOid] = $associatedId; $this->entityIdentifiers[$newValueOid] = $associatedId;
$this->identityMap[$targetClass->rootEntityName][$relatedIdHash] = $newValue; $this->identityMap[$targetClass->rootEntityName][$relatedIdHash] = $newValue;
if ($newValue instanceof NotifyPropertyChanged) { if (
$newValue instanceof NotifyPropertyChanged &&
( ! $newValue instanceof Proxy || $newValue->__isInitialized())
) {
$newValue->addPropertyChangedListener($this); $newValue->addPropertyChangedListener($this);
} }
$this->entityStates[$newValueOid] = self::STATE_MANAGED; $this->entityStates[$newValueOid] = self::STATE_MANAGED;
@ -3003,7 +3006,7 @@ class UnitOfWork implements PropertyChangedListener
$this->addToIdentityMap($entity); $this->addToIdentityMap($entity);
if ($entity instanceof NotifyPropertyChanged) { if ($entity instanceof NotifyPropertyChanged && ( ! $entity instanceof Proxy || $entity->__isInitialized())) {
$entity->addPropertyChangedListener($this); $entity->addPropertyChangedListener($this);
} }
} }

View File

@ -50,7 +50,14 @@ class DDC1690Test extends \Doctrine\Tests\OrmFunctionalTestCase
$child = $this->_em->find(__NAMESPACE__.'\DDC1690Child', $childId); $child = $this->_em->find(__NAMESPACE__.'\DDC1690Child', $childId);
$this->assertEquals(1, count($parent->listeners)); $this->assertEquals(1, count($parent->listeners));
$this->assertEquals(1, count($child->listeners)); $this->assertInstanceOf(
'Doctrine\\ORM\\Proxy\\Proxy',
$child,
'Verifying that $child is a proxy before using proxy API'
);
$this->assertCount(0, $child->listeners);
$child->__load();
$this->assertCount(1, $child->listeners);
unset($parent, $child); unset($parent, $child);
$parent = $this->_em->find(__NAMESPACE__.'\DDC1690Parent', $parentId); $parent = $this->_em->find(__NAMESPACE__.'\DDC1690Parent', $parentId);

View File

@ -0,0 +1,102 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Common\NotifyPropertyChanged;
use Doctrine\Common\PropertyChangedListener;
use Doctrine\ORM\Tools\ToolsException;
use Doctrine\Tests\OrmFunctionalTestCase;
/**
* @group DDC-2230
*/
class DDC2230Test extends OrmFunctionalTestCase
{
protected function setup()
{
parent::setup();
try {
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2230User'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2230Address'),
));
} catch (ToolsException $e) {}
}
public function testNotifyTrackingNotCalledOnUninitializedProxies()
{
$insertedUser = new DDC2230User();
$insertedUser->address = new DDC2230Address();
$this->_em->persist($insertedUser);
$this->_em->persist($insertedUser->address);
$this->_em->flush();
$this->_em->clear();
$user = $this->_em->find(__NAMESPACE__ . '\\DDC2230User', $insertedUser->id);
$this->_em->clear();
$mergedUser = $this->_em->merge($user);
/* @var $address \Doctrine\Common\Proxy\Proxy */
$address = $mergedUser->address;
$this->assertInstanceOf('Doctrine\\ORM\\Proxy\\Proxy', $address);
$this->assertFalse($address->__isInitialized());
}
public function testNotifyTrackingCalledOnProxyInitialization()
{
$insertedAddress = new DDC2230Address();
$this->_em->persist($insertedAddress);
$this->_em->flush();
$this->_em->clear();
$addressProxy = $this->_em->getReference(__NAMESPACE__ . '\\DDC2230Address', $insertedAddress->id);
/* @var $addressProxy \Doctrine\Common\Proxy\Proxy|\Doctrine\Tests\ORM\Functional\Ticket\DDC2230Address */
$this->assertFalse($addressProxy->__isInitialized());
$this->assertNull($addressProxy->listener);
$addressProxy->__load();
$this->assertSame($this->_em->getUnitOfWork(), $addressProxy->listener);
}
}
/** @Entity */
class DDC2230User
{
/** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */
public $id;
/**
* @OneToOne(targetEntity="DDC2230Address")
*/
public $address;
}
/**
* @Entity
* @ChangeTrackingPolicy("NOTIFY")
*/
class DDC2230Address implements NotifyPropertyChanged
{
/** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */
public $id;
/**
* @var \Doctrine\Common\PropertyChangedListener
*/
public $listener;
/** {@inheritDoc} */
function addPropertyChangedListener(PropertyChangedListener $listener)
{
$this->listener = $listener;
}
}