• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 2.0 XF:SessionActivity

LPH

Well-known member
#1
Outside of XenForo 2, the getOnlineUsersList is pulled. If the user logins to XenForo from outside XF 2 and hasn't browsed then the repository isn't showing that the user is in fact logged into the site. Once the account browses to XenForo 2 installation then the getOnlineUsersList is updated to show the user.

This is the code that I'm using.

PHP:
/** @var \XF\Repository\SessionActivity $activityRepo */
$activityRepo = \XF::app()->repository('XF:SessionActivity');
$onlineCount = $activityRepo->getOnlineCounts();
$onlineUserList = $activityRepo->getOnlineUsersList(50);
Pulling the SessionActivity in XenForo 1 worked fine; that is, once the person logged in then they were shown on the list. They never had to browse to the XF installation.

Am I doing something wrong in my reasoning? Should I try to use something else besides the repository?
 

Mike

XenForo developer
Staff member
#2
Unless you hit an actual XF "public" page, your session activity won't be updated. If you want that to happen elsewhere, you'd need to do it manually.

See XF\Pub\Controller\AbstractController::updateSessionActivity().
 

LPH

Well-known member
#3
Perfect !

Added the following line:
PHP:
$activityRepo->updateSessionActivity(
   \XF::visitor()->user_id, \XF::app()->request->getIp(),
   '', '', array(''), 'valid',
   ''
      );