From: joshuaruesweg Date: Mon, 26 Oct 2020 13:16:24 +0000 (+0100) Subject: Add new intern method to fetch sessions X-Git-Tag: 5.4.0_Alpha_1~656^2~13 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=684f70d3d5346859f78652b89ff11dcc899ac1ac;p=GitHub%2FWoltLab%2FWCF.git Add new intern method to fetch sessions --- diff --git a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php index 1231daae98..f1ab8b7071 100644 --- a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php +++ b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php @@ -989,49 +989,45 @@ final class SessionHandler extends SingletonFactory { * Returns all user sessions for a specific user. * * @return Session[] + * @throws \InvalidArgumentException if the given user is a guest. * @since 5.4 */ public function getUserSessions(User $user): array { - if ($user->userID === 0) { - throw new \InvalidArgumentException("The given user is a guest."); - } - - $sql = "SELECT * - FROM wcf".WCF_N."_user_session - WHERE userID = ?"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute([$user->userID]); - - $sessions = []; - - while ($row = $statement->fetchArray()) { - $sessions[] = new Session($row); - } - - return $sessions; + return $this->getSessions($user); } /** * Returns all acp sessions for a specific user. * * @return Session[] + * @throws \InvalidArgumentException if the given user is a guest. * @since 5.4 */ public function getAcpSessions(User $user): array { - if ($user->userID === 0) { + return $this->getSessions($user, true); + } + + /** + * Returns all sessions for a specific user. + * + * @return Session[] + * @throws \InvalidArgumentException if the given user is a guest. + * @since 5.4 + */ + private function getSessions(User $user, bool $isAcp = false): array { + if (!$user->userID) { throw new \InvalidArgumentException("The given user is a guest."); } $sql = "SELECT * - FROM wcf".WCF_N."_acp_session + FROM wcf".WCF_N."_". ($isAcp ? 'acp' : 'user') ."_session WHERE userID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([$user->userID]); $sessions = []; - while ($row = $statement->fetchArray()) { - $sessions[] = new Session($row, true); + $sessions[] = new Session($row, $isAcp); } return $sessions;