From 73d4dc26190694506adb195dbfe754bb3f8504ac Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Thu, 7 Apr 2022 11:23:57 -0100 Subject: [PATCH] update memberships on path change Signed-off-by: Maxence Lange --- lib/Service/MembershipService.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/Service/MembershipService.php b/lib/Service/MembershipService.php index 863831b16..769fd8926 100644 --- a/lib/Service/MembershipService.php +++ b/lib/Service/MembershipService.php @@ -303,17 +303,25 @@ function (Membership $item): string { /** + * Add the new membership if unknown or Update known membership if: + * - new membership comes with more power + * - level is the same, but inheritance is shorter + * * @param Membership $membership * @param Membership[] $memberships */ private function fillMemberships(Membership $membership, array &$memberships) { foreach ($memberships as $known) { if ($known->getCircleId() === $membership->getCircleId()) { - if ($known->getLevel() < $membership->getLevel()) { + if ($known->getLevel() < $membership->getLevel() + || ($known->getLevel() === $membership->getLevel() + && $known->getInheritanceDepth() > $membership->getInheritanceDepth()) + ) { $known->setLevel($membership->getLevel()); -// $known->setMemberId($membership->getMemberId()); - $known->setSingleId($membership->getSingleId()); + $known->setInheritanceFirst($membership->getInheritanceFirst()); $known->setInheritanceLast($membership->getInheritanceLast()); + $known->setInheritanceDepth($membership->getInheritanceDepth()); + $known->setInheritancePath($membership->getInheritancePath()); } return; @@ -363,7 +371,8 @@ private function createNewMemberships(array $memberships, array $known): array { foreach ($memberships as $membership) { try { $item = $this->getMembershipsFromList($known, $membership->getCircleId()); - if ($item->getLevel() !== $membership->getLevel()) { + if ($item->getLevel() !== $membership->getLevel() + || $item->getInheritanceDepth() !== $membership->getInheritanceDepth()) { $this->membershipRequest->update($membership); $new[] = $item; } elseif ($item->getInheritancePath() !== $membership->getInheritancePath()) {