1
0
Fork 0
mirror of synced 2025-04-03 13:23:37 +03:00

#1173 - applying CS fixes on top of the patch

This commit is contained in:
Marco Pivetta 2014-11-11 12:27:57 +01:00
parent 2ead9e23ab
commit 511893e182

View file

@ -1785,7 +1785,7 @@ class UnitOfWork implements PropertyChangedListener
$managedCopy = $visited[$oid]; $managedCopy = $visited[$oid];
if ($prevManagedCopy !== null) { if ($prevManagedCopy !== null) {
$this->updateAssociationWithMergedEntity($entity, $prevManagedCopy, $assoc, $managedCopy); $this->updateAssociationWithMergedEntity($entity, $assoc, $prevManagedCopy, $managedCopy);
} }
return $managedCopy; return $managedCopy;
@ -1939,7 +1939,7 @@ class UnitOfWork implements PropertyChangedListener
} }
if ($prevManagedCopy !== null) { if ($prevManagedCopy !== null) {
$this->updateAssociationWithMergedEntity($entity, $prevManagedCopy, $assoc, $managedCopy); $this->updateAssociationWithMergedEntity($entity, $assoc, $prevManagedCopy, $managedCopy);
} }
// Mark the managed copy visited as well // Mark the managed copy visited as well
@ -1951,27 +1951,33 @@ class UnitOfWork implements PropertyChangedListener
} }
/** /**
* Sets/adds associated managed copies into the previous entity's association field
*
* @param object $entity * @param object $entity
* @param object $prevManagedCopy * @param array $association
* @param array $assoc * @param object $previousManagedCopy
* @param object $managedCopy * @param object $managedCopy
*
* @return void
*/ */
private function updateAssociationWithMergedEntity($entity, $prevManagedCopy, array $assoc, $managedCopy) private function updateAssociationWithMergedEntity($entity, array $association, $previousManagedCopy, $managedCopy)
{ {
$assocField = $assoc['fieldName']; $assocField = $association['fieldName'];
$prevClass = $this->em->getClassMetadata(get_class($prevManagedCopy)); $prevClass = $this->em->getClassMetadata(get_class($previousManagedCopy));
if ($association['type'] & ClassMetadata::TO_ONE) {
$prevClass->reflFields[$assocField]->setValue($previousManagedCopy, $managedCopy);
if ($assoc['type'] & ClassMetadata::TO_ONE) {
$prevClass->reflFields[$assocField]->setValue($prevManagedCopy, $managedCopy);
return; return;
} }
$value = $prevClass->reflFields[$assocField]->getValue($prevManagedCopy); $value = $prevClass->reflFields[$assocField]->getValue($previousManagedCopy);
$value[] = $managedCopy; $value[] = $managedCopy;
if ($assoc['type'] == ClassMetadata::ONE_TO_MANY) { if ($association['type'] == ClassMetadata::ONE_TO_MANY) {
$class = $this->em->getClassMetadata(get_class($entity)); $class = $this->em->getClassMetadata(get_class($entity));
$class->reflFields[$assoc['mappedBy']]->setValue($managedCopy, $prevManagedCopy);
$class->reflFields[$association['mappedBy']]->setValue($managedCopy, $previousManagedCopy);
} }
} }