From 99ba6326833dc8b7848495c918b659d21ee728ce Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Sat, 24 Oct 2020 16:14:02 +0200 Subject: [PATCH] Add method to delete all acp sessions for a specific user --- .../system/session/SessionHandler.class.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php index 017a234bbc..5dad6eb8de 100644 --- a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php +++ b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php @@ -1013,6 +1013,28 @@ final class SessionHandler extends SingletonFactory { $statement->execute($conditionBuilder->getParameters()); } + /** + * Deletes the acp sessions for a specific user, except the session with the given session id. + * If the given session id is null or unknown, all acp sessions for the user will be deleted. + */ + public function deleteAcpSessionsExcept(User $user, ?string $sessionID = null): void { + if ($user->userID === 0) { + throw new \InvalidArgumentException("The given user is a guest."); + } + + $conditionBuilder = new PreparedStatementConditionBuilder(); + $conditionBuilder->add('userID = ?', [$user->userID]); + + if ($sessionID !== null) { + $conditionBuilder->add('sessionID <> ?', [$sessionID]); + } + + $sql = "DELETE FROM wcf".WCF_N."_acp_session + ". $conditionBuilder; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditionBuilder->getParameters()); + } + /** * Deletes a user session with the given session id. */ -- 2.20.1