@@ -266,17 +266,20 @@ public function getSessionsForCurrentUser()
266266 */
267267 public function logoutOtherUserSessions ()
268268 {
269- $ collection = $ this ->createAdminSessionInfoCollection ()
270- ->filterByUser (
271- $ this ->authSession ->getUser ()->getId (),
272- \Magento \Security \Model \AdminSessionInfo::LOGGED_IN ,
273- $ this ->authSession ->getAdminSessionInfoId ()
274- )
275- ->filterExpiredSessions ($ this ->securityConfig ->getAdminSessionLifetime ())
276- ->loadData ();
269+ $ user = $ this ->authSession ->getUser ();
270+ if ($ user ) {
271+ $ collection = $ this ->createAdminSessionInfoCollection ()
272+ ->filterByUser (
273+ $ user ->getId (),
274+ \Magento \Security \Model \AdminSessionInfo::LOGGED_IN ,
275+ $ this ->authSession ->getAdminSessionInfoId ()
276+ )
277+ ->filterExpiredSessions ($ this ->securityConfig ->getAdminSessionLifetime ())
278+ ->loadData ();
277279
278- $ collection ->setDataToAll ('status ' , \Magento \Security \Model \AdminSessionInfo::LOGGED_OUT_MANUALLY )
279- ->save ();
280+ $ collection ->setDataToAll ('status ' , \Magento \Security \Model \AdminSessionInfo::LOGGED_OUT_MANUALLY )
281+ ->save ();
282+ }
280283
281284 return $ this ;
282285 }
@@ -304,11 +307,12 @@ public function cleanExpiredSessions()
304307 */
305308 protected function createNewSession ()
306309 {
310+ $ user = $ this ->authSession ->getUser ();
307311 $ adminSessionInfo = $ this ->adminSessionInfoFactory
308312 ->create ()
309313 ->setData (
310314 [
311- 'user_id ' => $ this -> authSession -> getUser ()-> getId (),
315+ 'user_id ' => $ user ? $ user -> getId () : null ,
312316 'ip ' => $ this ->remoteAddress ->getRemoteAddress (),
313317 'status ' => AdminSessionInfo::LOGGED_IN
314318 ]
0 commit comments