From 10405f69c98635c7149bc6badfd3452c1f1db5e4 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Sun, 10 Sep 2017 18:12:51 +0200 Subject: [PATCH] Improved handling of overlapping paid subscriptions Closes #2418 --- .../user/PaidSubscriptionUserAction.class.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/wcfsetup/install/files/lib/data/paid/subscription/user/PaidSubscriptionUserAction.class.php b/wcfsetup/install/files/lib/data/paid/subscription/user/PaidSubscriptionUserAction.class.php index a9dfe65558..90cab722ab 100644 --- a/wcfsetup/install/files/lib/data/paid/subscription/user/PaidSubscriptionUserAction.class.php +++ b/wcfsetup/install/files/lib/data/paid/subscription/user/PaidSubscriptionUserAction.class.php @@ -133,13 +133,29 @@ class PaidSubscriptionUserAction extends AbstractDatabaseObjectAction { $this->readObjects(); } + $userIDs = []; foreach ($this->getObjects() as $subscriptionUser) { + $userIDs[] = $subscriptionUser->userID; $subscriptionUser->update(['isActive' => 0]); // update group memberships $action = new PaidSubscriptionUserAction([$subscriptionUser], 'removeGroupMemberships'); $action->executeAction(); } + + if (!empty($userIDs)) { + $userIDs = array_unique($userIDs); + + $subscriptionUserList = new PaidSubscriptionUserList(); + $subscriptionUserList->getConditionBuilder()->add('isActive = ?', [1]); + $subscriptionUserList->getConditionBuilder()->add('userID IN (?)', [$userIDs]); + $subscriptionUserList->readObjects(); + + if (count($subscriptionUserList->getObjects())) { + $action = new PaidSubscriptionUserAction($subscriptionUserList->getObjects(), 'addGroupMemberships'); + $action->executeAction(); + } + } } /** -- 2.20.1