Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #PHPCR-78 #158

Merged
merged 8 commits into from Aug 30, 2012
10 changes: 10 additions & 0 deletions lib/Doctrine/ODM/PHPCR/UnitOfWork.php
Expand Up @@ -1348,6 +1348,8 @@ private function executeInserts($documents)
} }
); );


$associationChangesets = array();

foreach ($oids as $oid => $id) { foreach ($oids as $oid => $id) {
$document = $documents[$oid]; $document = $documents[$oid];
$class = $this->dm->getClassMetadata(get_class($document)); $class = $this->dm->getClassMetadata(get_class($document));
Expand Down Expand Up @@ -1415,6 +1417,12 @@ private function executeInserts($documents)
} }
} elseif (isset($class->associationsMappings[$fieldName])) { } elseif (isset($class->associationsMappings[$fieldName])) {
$this->scheduledAssociationUpdates[$oid] = $document; $this->scheduledAssociationUpdates[$oid] = $document;

//populate $associationChangesets to force executeUpdates($this->scheduledAssociationUpdates)
//to only update association fields
$data = isset($associationChangesets[$oid]['fields']) ? $associationChangesets[$oid]['fields'] : array();
$data[$class->associationsMappings[$fieldName]['fieldName']] = $fieldValue;
$associationChangesets[$oid] = array('fields' => $data, 'reorderings' => array());
} }
} }


Expand All @@ -1427,6 +1435,8 @@ private function executeInserts($documents)
$this->evm->dispatchEvent(Event::postPersist, new LifecycleEventArgs($document, $this->dm)); $this->evm->dispatchEvent(Event::postPersist, new LifecycleEventArgs($document, $this->dm));
} }
} }

$this->documentChangesets = array_merge($this->documentChangesets, $associationChangesets);
} }


/** /**
Expand Down
127 changes: 127 additions & 0 deletions tests/Doctrine/Tests/ODM/PHPCR/Functional/ProtectedPropertyTest.php
@@ -0,0 +1,127 @@
<?php

namespace Doctrine\Tests\ODM\PHPCR\Functional;

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

/**
* @see http://www.doctrine-project.org/jira/browse/PHPCR-78
* @group functional
*/
class ProtectedPropertyTest extends \Doctrine\Tests\ODM\PHPCR\PHPCRFunctionalTestCase
{
/**
* @var \Doctrine\ODM\PHPCR\DocumentManager
*/
private $dm;

/**
* Class name of the document class
* @var string
*/
private $type;

/**
* @var \PHPCR\NodeInterface
*/
private $node;

public function setUp()
{
$this->dm = $this->createDocumentManager();
$this->node = $this->resetFunctionalNode($this->dm);

$session = $this->dm->getPhpcrSession();
if (! $session instanceof \Jackalope\Session) {
$this->markTestSkipped('Not a Jackalope session');
}

$cnd = <<<CND
<test='http://test.fr'>
[test:protected_property_test] > nt:hierarchyNode
- reference (REFERENCE)
CND;

$cnd2 = <<<CND
<test='http://test.fr'>
[test:protected_property_test2] > nt:hierarchyNode
- reference (REFERENCE)
- reference2 (REFERENCE)
CND;

$ntm = $session->getWorkspace()->getNodeTypeManager();
$ntm->registerNodeTypesCnd($cnd, true);
$ntm->registerNodeTypesCnd($cnd2, true);
}

public function testPersistDocumentWithReferenceAndProtectedProperty()
{
$object = new ProtectedPropertyTestObj();
$object->id = '/functional/pp';

try {
$this->dm->persist($object);
$this->dm->flush();
$this->dm->clear();
} catch(\PHPCR\NodeType\ConstraintViolationException $e) {
$this->fail(sprintf('A ConstraintViolationException has been thrown when persisting document ("%s").', $e->getMessage()));
}

$this->assertTrue(true);
}

public function testPersistDocumentWithSeveralReferencesAndProtectedProperty()
{
$object = new ProtectedPropertyTestObj2();
$object->id = '/functional/pp';

try {
$this->dm->persist($object);
$this->dm->flush();
$this->dm->clear();
} catch(\PHPCR\NodeType\ConstraintViolationException $e) {
$this->fail(sprintf('A ConstraintViolationException has been thrown when persisting document ("%s").', $e->getMessage()));
}

$this->assertTrue(true);
}
}

/**
* @PHPCRODM\Document(nodeType="test:protected_property_test")
*/
class ProtectedPropertyTestObj
{
/** @PHPCRODM\Id() */
public $id;

/** @PHPCRODM\ReferenceOne(strategy="hard") */
public $reference;

/** @PHPCRODM\Date(name="jcr:created") */
public $created;

/** @PHPCRODM\String(name="jcr:createdBy") */
public $createdBy;
}

/**
* @PHPCRODM\Document(nodeType="test:protected_property_test2")
*/
class ProtectedPropertyTestObj2
{
/** @PHPCRODM\Id() */
public $id;

/** @PHPCRODM\ReferenceOne(strategy="hard") */
public $reference;

/** @PHPCRODM\ReferenceOne(strategy="hard") */
public $reference2;

/** @PHPCRODM\Date(name="jcr:created") */
public $created;

/** @PHPCRODM\String(name="jcr:createdBy") */
public $createdBy;
}