From 612f84ec1bdfddaaab036736228e8f14f3cc2808 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 1 Oct 2020 11:46:07 +0200 Subject: [PATCH] Remove `createNewSession` variable in SessionHandler::create() This always was `true` since the previous commits. --- .../system/session/SessionHandler.class.php | 75 +++++++++---------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php index e50fb1a3d2..bb21b77a5d 100644 --- a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php +++ b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php @@ -544,52 +544,49 @@ class SessionHandler extends SingletonFactory { $this->user = new User(null); - $createNewSession = true; $session = null; - if ($createNewSession) { - // save session - $sessionData = [ - 'sessionID' => $sessionID, - 'userID' => $this->user->userID, - 'ipAddress' => UserUtil::getIpAddress(), - 'userAgent' => UserUtil::getUserAgent(), - 'lastActivityTime' => TIME_NOW, - 'requestURI' => UserUtil::getRequestURI(), - 'requestMethod' => !empty($_SERVER['REQUEST_METHOD']) ? substr($_SERVER['REQUEST_METHOD'], 0, 7) : '' - ]; - - if ($spiderID !== null) $sessionData['spiderID'] = $spiderID; - - try { - $this->session = call_user_func([$this->sessionEditorClassName, 'create'], $sessionData); - } - catch (DatabaseException $e) { - // MySQL error 23000 = unique key - // do not check against the message itself, some weird systems localize them - if ($e->getCode() == 23000) { - // find existing session - $session = call_user_func([$this->sessionClassName, 'getSessionByUserID'], $this->user->userID); - - if ($session === null) { - // MySQL reported a unique key error, but no corresponding session exists, rethrow exception - throw $e; - } - else { - // inherit existing session - $this->session = $session; - $this->loadVirtualSession(true); - } + // save session + $sessionData = [ + 'sessionID' => $sessionID, + 'userID' => $this->user->userID, + 'ipAddress' => UserUtil::getIpAddress(), + 'userAgent' => UserUtil::getUserAgent(), + 'lastActivityTime' => TIME_NOW, + 'requestURI' => UserUtil::getRequestURI(), + 'requestMethod' => !empty($_SERVER['REQUEST_METHOD']) ? substr($_SERVER['REQUEST_METHOD'], 0, 7) : '' + ]; + + if ($spiderID !== null) $sessionData['spiderID'] = $spiderID; + + try { + $this->session = call_user_func([$this->sessionEditorClassName, 'create'], $sessionData); + } + catch (DatabaseException $e) { + // MySQL error 23000 = unique key + // do not check against the message itself, some weird systems localize them + if ($e->getCode() == 23000) { + // find existing session + $session = call_user_func([$this->sessionClassName, 'getSessionByUserID'], $this->user->userID); + + if ($session === null) { + // MySQL reported a unique key error, but no corresponding session exists, rethrow exception + throw $e; } else { - // unrelated to user id - throw $e; + // inherit existing session + $this->session = $session; + $this->loadVirtualSession(true); } } - - $this->firstVisit = true; - $this->loadVirtualSession(true); + else { + // unrelated to user id + throw $e; + } } + + $this->firstVisit = true; + $this->loadVirtualSession(true); } /** -- 2.20.1