Skip to content

Commit

Permalink
Merge pull request doctrine#513 from asiragusa/master
Browse files Browse the repository at this point in the history
Fixed a bug while moving the node to a new parent and the @nodename has ...
  • Loading branch information
dbu committed Jun 23, 2014
2 parents 68b66b8 + c2a37a2 commit 041b3d2
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/PHPCR/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ public function computeChangeSet(ClassMetadata $class, $document)
: PathHelper::getParentPath($this->getDocumentId($document));
}
if (false === $destName) {
$destName = $changeSet[$class->nodename]
$destName = $class->nodename !== null && $changeSet[$class->nodename]
? $changeSet[$class->nodename]
: PathHelper::getNodeName($this->getDocumentId($document));
}
Expand Down
28 changes: 28 additions & 0 deletions tests/Doctrine/Tests/Models/References/ParentNoNodeNameTestObj.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Doctrine\Tests\Models\References;

use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;

/**
* @PHPCRODM\Document(referenceable=true)
*/
class ParentNoNodeNameTestObj
{
/** @PHPCRODM\Id */
public $id;
/** @PHPCRODM\ParentDocument */
public $parent;
/** @PHPCRODM\String */
public $name;

public function getParentDocument()
{
return $this->parent;
}

public function setParentDocument($parent)
{
$this->parent = $parent;
}
}
36 changes: 36 additions & 0 deletions tests/Doctrine/Tests/ODM/PHPCR/Functional/UnitOfWorkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Doctrine\ODM\PHPCR\UnitOfWork;
use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\Models\CMS\CmsAddress;
use Doctrine\Tests\Models\References\ParentNoNodeNameTestObj;
use Doctrine\Tests\Models\References\ParentTestObj;

use Doctrine\Tests\Models\Translation\Comment;

Expand Down Expand Up @@ -78,6 +80,40 @@ public function testSchedules()
$this->assertEquals(32, strlen(key($scheduledMoves)), 'Size of key is 32 chars (oid)');
$this->assertEquals(array($user1, '/foobar'), current($scheduledMoves));
}

public function testMoveParentNoNodeName() {
$root = $this->dm->find(null, 'functional');

$parent1 = new ParentTestObj();
$parent1->nodename = "root1";
$parent1->name = "root1";
$parent1->setParentDocument($root);

$parent2 = new ParentTestObj();
$parent2->name = "/root2";
$parent2->nodename = "root2";
$parent2->setParentDocument($root);

$child = new ParentNoNodeNameTestObj();
$child->setParentDocument($parent1);
$child->name = "child";

$this->dm->persist($parent1);
$this->dm->persist($parent2);
$this->dm->persist($child);

$this->dm->flush();

$child->setParentDocument($parent2);

$this->dm->persist($child);

try {
$this->dm->flush();
} catch (\Exception $e) {
$this->fail('An exception has been raised moving a child node from parent1 to parent2.');
}
}

public function testGetScheduledReorders()
{
Expand Down

0 comments on commit 041b3d2

Please sign in to comment.