[ticket/16470] Update user last visit time on session begin

Update user last visit time on session begin same way as on session create.

PHPBB3-16470
PHPBB3-14173
This commit is contained in:
rxu 2023-06-11 14:55:30 +07:00
parent 75dcbeaa9f
commit aafb522538
No known key found for this signature in database
GPG key ID: 955F0567380E586A

View file

@ -440,6 +440,12 @@ class session
// Is user banned? Are they excluded? Won't return on ban, exists within method
$this->check_ban_for_current_session($config);
// Update user last visit time accordingly, but in a minute or so
if ($this->time_now - $this->data['session_time'] > 60)
{
$this->update_user_lastvisit();
}
return true;
}
}
@ -684,14 +690,11 @@ class session
{
$this->session_id = $this->data['session_id'];
// Only update session DB a minute or so after last update or if page changes
// Only sync user last visit time in a minute or so after last session data update or if the page changes
if ($this->time_now - $this->data['session_time'] > 60 || ($this->update_session_page && $this->data['session_page'] != $this->page['page']))
{
// Update the last visit time
$sql = 'UPDATE ' . USERS_TABLE . '
SET user_lastvisit = ' . (int) $this->data['session_time'] . '
WHERE user_id = ' . (int) $this->data['user_id'];
$db->sql_query($sql);
$this->update_user_lastvisit();
}
$SID = '?sid=';
@ -1797,4 +1800,28 @@ class session
{
return isset($this->data['user_id']) ? (int) $this->data['user_id'] : ANONYMOUS;
}
/**
* Update user last visit time
*
* @return bool
*/
public function update_user_lastvisit()
{
global $db;
if (!isset($this->data['session_time'], $this->data['user_id']))
{
return false;
}
$sql = 'UPDATE ' . USERS_TABLE . '
SET user_lastvisit = ' . (int) $this->data['session_time'] . '
WHERE user_id = ' . (int) $this->data['user_id'];
if ($db->sql_query($sql))
{
return true;
}
}
}