XF 2.2 How to increase online status timeout?

clubpromos

Active member
Hi,

For a long time now, I've used the method in this post to increase the online status timeout to 4 hours instead of just 60 minutes.
Since I upgraded to XF 2.2.8 Patch 1, this no longer works.
It looks like something has changed in SessionActivity.php and I can't figure it out.

Can someone help figure this one out?

Thank you!
 
First make ab backup copy: /src/XF/Repository/SessionActivity.php
Then edit your /src/config.php
Set:
$config['development']['enabled'] = false;
to
$config['development']['enabled'] = true;
add it if it's not there. Save the file.

Then goto your AdminCP:
/admin.php?options/groups/users/
Set this and the other below from 60 to: 240 (Minutes)
1643697030419.png
1643697108398.png
Save your new settings...


Then:
edit: /src/XF/Repository/SessionActivity.php
Code:
//change this:
class SessionActivity extends Repository
{
    public function getOnlineCounts($onlineCutOff = null)
    {
        if ($onlineCutOff === null)
        {
            $onlineCutOff = \XF::$time - $this->options()->onlineStatusTimeout * 60;
        }

        return $this->db()->fetchRow("
            SELECT
                SUM(IF(user_id >= 0 AND robot_key = '', 1, 0)) AS total,
                SUM(IF(user_id > 0, 1, 0)) AS members,
                SUM(IF(user_id = 0 AND robot_key = '', 1, 0)) AS guests
            FROM xf_session_activity
            WHERE view_date >= ?
        ", $onlineCutOff);
    }

//To his one:
class SessionActivity extends Repository
{
    public function getOnlineCounts($onlineCutOff = null)
    {
        if ($onlineCutOff === null)
        {
            $onlineCutOff = \XF::$time - $this->options()->onlineStatusTimeout * 240;
        }

        return $this->db()->fetchRow("
            SELECT
                SUM(IF(user_id >= 0 AND robot_key = '', 1, 0)) AS total,
                SUM(IF(user_id > 0, 1, 0)) AS members,
                SUM(IF(user_id = 0 AND robot_key = '', 1, 0)) AS guests
            FROM xf_session_activity
            WHERE view_date >= ?
        ", $onlineCutOff);
    }

And this function (pruneExpiredActivityRecords($cutOff = null)) to:

public function pruneExpiredActivityRecords($cutOff = null)
    {
        if ($cutOff === null)
        {
            $expiration = $this->getDefaultSessionActivityExpiration();
            if (!$expiration)
            {
                return;
            }

            $cutOff = \XF::$time - 14400;
        }

        $this->db()->delete('xf_session_activity', 'view_date < ?', $cutOff);
    }

Then edit your /src/config.php
Set:
$config['development']['enabled'] = true;
to
$config['development']['enabled'] = false;

Save the file.

All changes made here relate to a display of 4 hours and XF version 2.2.7 / 2.2.8
The changes must be made again after each upgrade.

Warning!
As an admin or moderator, always log out explicitly and never remain logged in with these changes longer than necessary!
The longer a user with special rights is logged in, the easier it is for attackers to calculate certain data and, for example, to take over an admin or moderator account.

Hth
 
Top Bottom