diff --git a/lib/Exception/DeletingUserWithActiveSubscriptionException.php b/lib/Exception/DeletingUserWithActiveSubscriptionException.php new file mode 100644 index 0000000000000000000000000000000000000000..edbc393b7e3a76f61f775d5d0c5c2f8a28a71630 --- /dev/null +++ b/lib/Exception/DeletingUserWithActiveSubscriptionException.php @@ -0,0 +1,9 @@ +getUser(); $email = $user->getEMailAddress(); $uid = $user->getUID(); + + // Handle shop accounts first; none of the other things should happen before the active subscription check + $this->handleShopAccounts($uid, $email); + $isUserOnLDAP = $this->LDAPConnectionService->isUserOnLDAPBackend($user); $this->logger->info("PostDelete user {user}", array('user' => $uid)); @@ -58,12 +63,22 @@ class BeforeUserDeletedListener implements IEventListener { } catch (Exception $e) { $this->logger->error('Error deleting aliases for user '. $uid . ' :' . $e->getMessage()); } + } + private function handleShopAccounts(string $uid, string $email) { $deleteShopAccount = $this->shopAccountService->getShopDeletePreference($uid); $shopUsers = $this->shopAccountService->getUsers($email); if (!empty($shopUsers)) { foreach ($shopUsers as $shopUser) { + if ($shopUser['has_active_subscription']) { + throw new DeletingUserWithActiveSubscriptionException('Cannot delete user ' . $uid . ' as an active subscription exists'); + } + + if (!isset($shopUser['id'])) { + continue; + } + if ($deleteShopAccount) { $this->shopAccountService->deleteUser($shopUser['shop_url'], $shopUser['id']); } else {