@@ -266,17 +266,20 @@ public function getSessionsForCurrentUser()
266
266
*/
267
267
public function logoutOtherUserSessions ()
268
268
{
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 ();
277
279
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
+ }
280
283
281
284
return $ this ;
282
285
}
@@ -304,11 +307,12 @@ public function cleanExpiredSessions()
304
307
*/
305
308
protected function createNewSession ()
306
309
{
310
+ $ user = $ this ->authSession ->getUser ();
307
311
$ adminSessionInfo = $ this ->adminSessionInfoFactory
308
312
->create ()
309
313
->setData (
310
314
[
311
- 'user_id ' => $ this -> authSession -> getUser ()-> getId (),
315
+ 'user_id ' => $ user ? $ user -> getId () : null ,
312
316
'ip ' => $ this ->remoteAddress ->getRemoteAddress (),
313
317
'status ' => AdminSessionInfo::LOGGED_IN
314
318
]
0 commit comments