Skip to content

Commit

Permalink
update memberships on path change
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Apr 11, 2022
1 parent 8589063 commit 73d4dc2
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/Service/MembershipService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit 73d4dc2

Please sign in to comment.