Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix DDC-1690 #541

Merged
merged 3 commits into from

4 participants

@PSchwisow

Added the lines suggested by the original reporter.

@PSchwisow PSchwisow Fix DDC-1690
Added the lines suggested by the original reporter.
5627993
@doctrinebot
Collaborator

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DDC-2211

lib/Doctrine/ORM/UnitOfWork.php
@@ -2573,6 +2573,9 @@ public function createEntity($className, array $data, &$hints = array())
$newValueOid = spl_object_hash($newValue);
$this->entityIdentifiers[$newValueOid] = $associatedId;
$this->identityMap[$targetClass->rootEntityName][$relatedIdHash] = $newValue;
+ if ($newValue instanceof NotifyPropertyChanged) {
@FabioBatSilva Owner

Missing line before conditional expression

I'm not sure what you mean about a missing line.

@FabioBatSilva Owner

you should keep a empty line before if

<?php
$this->identityMap[$targetClass->rootEntityName][$relatedIdHash] = $newValue;
// empty line
if ($newValue instanceof NotifyPropertyChanged) {
    $newValue->addPropertyChangedListener($this);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@FabioBatSilva

Hi @PSchwisow
Could you add a test case please ?

@beberlei beberlei merged commit 015771f into doctrine:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 20, 2012
  1. @PSchwisow

    Fix DDC-1690

    PSchwisow authored
    Added the lines suggested by the original reporter.
Commits on Dec 21, 2012
  1. [DDC-1690] Created unit test

    Patrick Schwisow authored
  2. @PSchwisow
This page is out of date. Refresh to see the latest.
View
4 lib/Doctrine/ORM/UnitOfWork.php
@@ -2573,6 +2573,10 @@ public function createEntity($className, array $data, &$hints = array())
$newValueOid = spl_object_hash($newValue);
$this->entityIdentifiers[$newValueOid] = $associatedId;
$this->identityMap[$targetClass->rootEntityName][$relatedIdHash] = $newValue;
+
+ if ($newValue instanceof NotifyPropertyChanged) {
+ $newValue->addPropertyChangedListener($this);
+ }
$this->entityStates[$newValueOid] = self::STATE_MANAGED;
// make sure that when an proxy is then finally loaded, $this->originalEntityData is set also!
break;
View
153 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php
@@ -0,0 +1,153 @@
+<?php
+namespace Doctrine\Tests\ORM\Functional\Ticket;
+
+use Doctrine\Common\NotifyPropertyChanged,
+ Doctrine\Common\PropertyChangedListener;
+
+require_once __DIR__ . '/../../../TestInit.php';
+
+class DDC1690Test extends \Doctrine\Tests\OrmFunctionalTestCase
+{
+ protected function setUp() {
+ parent::setUp();
+ try {
+ $this->_schemaTool->createSchema(array(
+ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1690Parent'),
+ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1690Child')
+ ));
+ } catch (\Exception $e) {
+ // Swallow all exceptions. We do not test the schema tool here.
+ }
+ }
+
+ public function testChangeTracking()
+ {
+ $parent = new DDC1690Parent();
+ $child = new DDC1690Child();
+ $parent->setName('parent');
+ $child->setName('child');
+
+ $parent->setChild($child);
+ $child->setParent($parent);
+
+ $this->_em->persist($parent);
+ $this->_em->persist($child);
+
+ $this->assertEquals(1, count($parent->listeners));
+ $this->assertEquals(1, count($child->listeners));
+
+ $this->_em->flush();
+ $this->_em->clear();
+
+ $this->assertEquals(1, count($parent->listeners));
+ $this->assertEquals(1, count($child->listeners));
+
+ $parentId = $parent->getId();
+ $childId = $child->getId();
+ unset($parent, $child);
+
+ $parent = $this->_em->find(__NAMESPACE__.'\DDC1690Parent', $parentId);
+ $child = $this->_em->find(__NAMESPACE__.'\DDC1690Child', $childId);
+
+ $this->assertEquals(1, count($parent->listeners));
+ $this->assertEquals(1, count($child->listeners));
+ unset($parent, $child);
+
+ $parent = $this->_em->find(__NAMESPACE__.'\DDC1690Parent', $parentId);
+ $child = $parent->getChild();
+
+ $this->assertEquals(1, count($parent->listeners));
+ $this->assertEquals(1, count($child->listeners));
+ unset($parent, $child);
+
+ $child = $this->_em->find(__NAMESPACE__.'\DDC1690Child', $childId);
+ $parent = $child->getParent();
+
+ $this->assertEquals(1, count($parent->listeners));
+ $this->assertEquals(1, count($child->listeners));
+ }
+}
+
+class NotifyBaseEntity implements NotifyPropertyChanged {
+ public $listeners = array();
+
+ public function addPropertyChangedListener(PropertyChangedListener $listener) {
+ if (!in_array($listener, $this->listeners)) {
+ $this->listeners[] = $listener;
+ }
+ }
+
+ protected function onPropertyChanged($propName, $oldValue, $newValue) {
+ if ($this->listeners) {
+ foreach ($this->listeners as $listener) {
+ $listener->propertyChanged($this, $propName, $oldValue, $newValue);
+ }
+ }
+ }
+}
+
+/** @Entity @ChangeTrackingPolicy("NOTIFY") */
+class DDC1690Parent extends NotifyBaseEntity {
+ /** @Id @Column(type="integer") @GeneratedValue */
+ private $id;
+
+ /** @Column */
+ private $name;
+
+ /** @OneToOne(targetEntity="DDC1690Child") */
+ private $child;
+
+ function getId() {
+ return $this->id;
+ }
+
+ function getName() {
+ return $this->name;
+ }
+
+ function setName($name) {
+ $this->onPropertyChanged('name', $this->name, $name);
+ $this->name = $name;
+ }
+
+ function setChild($child) {
+ $this->child = $child;
+ }
+
+ function getChild() {
+ return $this->child;
+ }
+}
+
+/** @Entity */
+class DDC1690Child extends NotifyBaseEntity {
+ /** @Id @Column(type="integer") @GeneratedValue */
+ private $id;
+
+ /** @Column */
+ private $name;
+
+ /** @OneToOne(targetEntity="DDC1690Parent", mappedBy="child") */
+ private $parent;
+
+ function getId() {
+ return $this->id;
+ }
+
+ function getName() {
+ return $this->name;
+ }
+
+ function setName($name) {
+ $this->onPropertyChanged('name', $this->name, $name);
+ $this->name = $name;
+ }
+
+ function setParent($parent) {
+ $this->parent = $parent;
+ }
+
+ function getParent() {
+ return $this->parent;
+ }
+}
Something went wrong with that request. Please try again.