Skip to content

Commit

Permalink
fix inferReciprocalComponent called on unsaved
Browse files Browse the repository at this point in the history
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 5e069ec
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/RecursivePublishable.php
Expand Up @@ -199,18 +199,20 @@ public function findOwnersRecursive($recursive, $list, $lookup)
$owner = $this->owner; $owner = $this->owner;
$owners = $owner->findRelatedObjects('owned_by', false); $owners = $owner->findRelatedObjects('owned_by', false);


// Second pass: Find owners via reverse lookup list // Second pass: Find owners via reverse lookup list if possible
foreach ($lookup as $ownedClass => $classLookups) { if ($owner->ID) {
// Skip owners of other objects foreach ($lookup as $ownedClass => $classLookups) {
if (!is_a($this->owner, $ownedClass)) { // Skip owners of other objects
continue; if (!is_a($owner, $ownedClass)) {
} continue;
foreach ($classLookups as $classLookup) { }
// Merge new owners into this object's owners foreach ($classLookups as $classLookup) {
$ownerClass = $classLookup['class']; // Merge new owners into this object's owners
$ownerRelation = $classLookup['relation']; $ownerClass = $classLookup['class'];
$result = $this->owner->inferReciprocalComponent($ownerClass, $ownerRelation); $ownerRelation = $classLookup['relation'];
$owner->mergeRelatedObjects($owners, $result); $result = $owner->inferReciprocalComponent($ownerClass, $ownerRelation);
$owner->mergeRelatedObjects($owners, $result);
}
} }
} }


Expand Down

0 comments on commit 5e069ec

Please sign in to comment.