Back to MetadataManager class

Method updateSessionRecord

private void
updateSessionRecord
(\Joomla\Session\SessionInterface $session, \Joomla\CMS\User\User $user)
Update the session record
Parameters
  • \Joomla\Session\SessionInterface $session The session to update the metadata record for.
  • \Joomla\CMS\User\User $user The user to associate with the record.
Returns
  • void
Since
  • 4.0.0

Method updateSessionRecord - Source code

/**
 * Update the session record
 *
 * @param   SessionInterface  $session  The session to update the metadata record for.
 * @param   User              $user     The user to associate with the record.
 *
 * @return  void
 *
 * @since   4.0.0
 */
private function updateSessionRecord(SessionInterface $session, User $user)
{
    $query = $this->db->getQuery(true);
    $time = time();
    $setValues = [$this->db->quoteName('guest') . ' = :guest', $this->db->quoteName('time') . ' = :time', $this->db->quoteName('userid') . ' = :user_id', $this->db->quoteName('username') . ' = :username'];
    // Bind query values
    $sessionId = $session->getId();
    $userIsGuest = $user->guest;
    $userId = $user->id;
    $username = $user->username === null ? '' : $user->username;
    $query->bind(':session_id', $sessionId)->bind(':guest', $userIsGuest, ParameterType::INTEGER)->bind(':time', $time)->bind(':user_id', $userId, ParameterType::INTEGER)->bind(':username', $username);
    if ($this->app instanceof CMSApplication && !$this->app->get('shared_session', false)) {
        $clientId = $this->app->getClientId();
        $setValues[] = $this->db->quoteName('client_id') . ' = :client_id';
        $query->bind(':client_id', $clientId, ParameterType::INTEGER);
    }
    $query->update($this->db->quoteName('#__session'))->set($setValues)->where($this->db->quoteName('session_id') . ' = :session_id');
    $this->db->setQuery($query);
    try {
        $this->db->execute();
    } catch (ExecutionFailureException $e) {
        // This failure isn't critical, we can go on without the metadata
    }
}