Skip to content

Commit

Permalink
Merge pull request phpbb#6698 from marc1706/ticket/17375
Browse files Browse the repository at this point in the history
[ticket/17375] Ensure user last visit does not get updated for active sessions in session gc
  • Loading branch information
marc1706 committed Aug 1, 2024
2 parents 56c1b9b + 18c00a9 commit b7ffee0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions phpBB/phpbb/session.php
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ function session_create($user_id = false, $set_admin = false, $persist_login = f
// Update the form key
$sql = 'UPDATE ' . USERS_TABLE . '
SET user_form_salt = \'' . $db->sql_escape($this->data['user_form_salt']) . '\',
user_last_active = ' . (int) $this->data['session_time'] . '
user_last_active = ' . (int) $this->time_now . '
WHERE user_id = ' . (int) $this->data['user_id'];
$db->sql_query($sql);
}
Expand Down Expand Up @@ -964,16 +964,17 @@ function session_gc()
}

/**
* Get most recent session for each registered user to sync user last visit with it
* Inner SELECT gets most recent sessions for each unique session_user_id
* Get expired sessions for registered users, only most recent for each user
* Inner SELECT gets most recent expired sessions for unique session_user_id
* Outer SELECT gets data for them
*/
$sql_select = 'SELECT s1.session_page, s1.session_user_id, s1.session_time AS recent_time
FROM ' . SESSIONS_TABLE . ' AS s1
INNER JOIN (
SELECT session_user_id, MAX(session_time) AS recent_time
FROM ' . SESSIONS_TABLE . '
WHERE session_user_id <> ' . ANONYMOUS . '
WHERE session_time < ' . ($this->time_now - (int) $config['session_length']) . '
AND session_user_id <> ' . ANONYMOUS . '
GROUP BY session_user_id
) AS s2
ON s1.session_user_id = s2.session_user_id
Expand Down

0 comments on commit b7ffee0

Please sign in to comment.