Skip to content
Permalink
Browse files

fix inferReciprocalComponent called on unsaved

DataObject::inferReciprocalComponent  cannot be called on object without IDs. There is currently no checks if owner has a proper id, which could result on errors.
Also use $owner instead of $this->owner for consistency in the function.

to be honest, I'm not sure how I managed to do that, but this extra check cannot hurt in my opinion.
  • Loading branch information...
lekoala committed Sep 24, 2018
1 parent e44954d commit 5e069ec85c3b3cb74054b5cc18012531cfe22ce6
Showing with 14 additions and 12 deletions.
  1. +14 −12 src/RecursivePublishable.php
@@ -199,18 +199,20 @@ public function findOwnersRecursive($recursive, $list, $lookup)
$owner = $this->owner;
$owners = $owner->findRelatedObjects('owned_by', false);
// Second pass: Find owners via reverse lookup list
foreach ($lookup as $ownedClass => $classLookups) {
// Skip owners of other objects
if (!is_a($this->owner, $ownedClass)) {
continue;
}
foreach ($classLookups as $classLookup) {
// Merge new owners into this object's owners
$ownerClass = $classLookup['class'];
$ownerRelation = $classLookup['relation'];
$result = $this->owner->inferReciprocalComponent($ownerClass, $ownerRelation);
$owner->mergeRelatedObjects($owners, $result);
// Second pass: Find owners via reverse lookup list if possible
if ($owner->ID) {
foreach ($lookup as $ownedClass => $classLookups) {
// Skip owners of other objects
if (!is_a($owner, $ownedClass)) {
continue;
}
foreach ($classLookups as $classLookup) {
// Merge new owners into this object's owners
$ownerClass = $classLookup['class'];
$ownerRelation = $classLookup['relation'];
$result = $owner->inferReciprocalComponent($ownerClass, $ownerRelation);
$owner->mergeRelatedObjects($owners, $result);
}
}
}

0 comments on commit 5e069ec

Please sign in to comment.
You can’t perform that action at this time.