Skip to content

Commit

Permalink
do not rely on the identifier being mapped
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed Mar 12, 2012
1 parent 3bebf71 commit 07a4d54
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lib/Doctrine/ODM/PHPCR/UnitOfWork.php
Expand Up @@ -547,7 +547,7 @@ private function cascadeScheduleInsert($class, $document, &$visited)
}
}

$id = $class->getIdentifierValue($document);
$id = $this->getDocumentId($document);
foreach ($class->childMappings as $childName => $mapping) {
$child = $class->reflFields[$childName]->getValue($document);
if ($child !== null && $this->getDocumentState($child) === self::STATE_NEW) {
Expand Down Expand Up @@ -803,7 +803,7 @@ private function computeChangeSet(ClassMetadata $class, $document)
&& isset($actualData[$class->parentMapping])
&& $this->originalData[$oid][$class->parentMapping] !== $actualData[$class->parentMapping]
) {
throw new PHPCRException('The ParentDocument property is immutable ('.$class->getIdentifierValue($this->originalData[$oid][$class->parentMapping]).' !== '.$class->getIdentifierValue($actualData[$class->parentMapping]).'). Please use PHPCR\Session::move to move the document: '.self::objToStr($document, $this->dm));
throw new PHPCRException('The ParentDocument property is immutable ('.$this->getDocumentId($this->originalData[$oid][$class->parentMapping]).' !== '.$this->getDocumentId($actualData[$class->parentMapping]).'). Please use PHPCR\Session::move to move the document: '.self::objToStr($document, $this->dm));
}
if (isset($this->originalData[$oid][$class->identifier])
&& isset($actualData[$class->identifier])
Expand Down Expand Up @@ -868,7 +868,7 @@ private function computeChangeSet(ClassMetadata $class, $document)
}
}

$id = $class->getIdentifierValue($document);
$id = $this->getDocumentId($document);
foreach ($class->childMappings as $name => $childMapping) {
if ($actualData[$name]) {
if ($this->originalData[$oid][$name] && $this->originalData[$oid][$name] !== $actualData[$name]) {
Expand Down Expand Up @@ -1402,8 +1402,7 @@ private function executeMoves($documents)

list($document, $targetPath) = $value;

$class = $this->dm->getClassMetadata(get_class($document));
$path = $class->getIdentifierValue($document);
$path = $this->getDocumentId($document);
if ($path === $targetPath) {
continue;
}
Expand Down Expand Up @@ -1772,7 +1771,7 @@ public function getDocumentId($document)
if (empty($this->documentIds[$oid])) {
$msg = 'Document is not managed and has no id';
if (is_object($document)) {
$msg.= ': '.self::objToStr($document, $this->dm);
$msg.= ': '.self::objToStr($document);
}
throw new PHPCRException($msg);
}
Expand Down Expand Up @@ -2013,10 +2012,8 @@ private static function objToStr($obj, DocumentManager $dm = null)

if ($dm) {
try {
$metadata = $dm->getClassMetadata(get_class($obj));
if ($metadata->getIdentifierValue($obj)) {
$string .= ' ('.$metadata->getIdentifierValue($obj).')';
}
$id = $dm->getUnitOfWork()->getDocumentId($obj);
$string .= " ($id)";
} catch (\Exception $e) {
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Doctrine/Tests/ODM/PHPCR/UnitOfWorkTest.php
Expand Up @@ -115,6 +115,8 @@ public function testScheduleInsertCancelsScheduleRemove()
$object->username = "bar";
$object->id = '/somepath';

$this->uow->scheduleInsert($object);

$this->uow->scheduleRemove($object);

$method = new \ReflectionMethod($this->uow, 'getDocumentState');
Expand Down

0 comments on commit 07a4d54

Please sign in to comment.