Skip to content

Commit

Permalink
Merge 46985e8 into d223d73
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtificialOwl authored Apr 7, 2022
2 parents d223d73 + 46985e8 commit 114e13b
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 114e13b

Please sign in to comment.