Skip to content

Commit

Permalink
[ticket/16470] Update user last visit time on session begin
Browse files Browse the repository at this point in the history
Update user last visit time on session begin same way as on session create.

PHPBB3-16470
  • Loading branch information
rxu committed Jun 11, 2023
1 parent 75dcbea commit 8f61a7c
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions phpBB/phpbb/session.php
Expand Up @@ -440,6 +440,12 @@ function session_begin($update_session_page = true)
// 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;
}
}
Expand Down Expand Up @@ -684,14 +690,11 @@ function session_create($user_id = false, $set_admin = false, $persist_login = f
{
$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=';
Expand Down Expand Up @@ -1797,4 +1800,28 @@ public function id() : int
{
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;
}
}
}

0 comments on commit 8f61a7c

Please sign in to comment.