Skip to content
Last updated

WHMCS\User\AdminLog

Class · extends AbstractModel

An administrative user login

Each log entry in this table represents a single login session for an administrative user.

Constants

NameDescription
ONLINE_WINDOW_MINUTESThe number of minutes since a visit within which an admin user is still considered to be online.

Properties

TypeNameDescription
``$timestamps
``$unique

Methods

getOnlineCutOff

public static function getOnlineCutOff(): string

The time before which a visit no longer counts as being online.

Deliberately evaluated in PHP rather than with the database's NOW(), because every lastvisit value is written by PHP: update_query() and insert_query() expand "now()" to date('YmdHis') rather than passing it to the database. Comparing PHP written values against the database clock would make admin users permanently online, or permanently offline, wherever the two time zones differ.

Returns string — A "Y-m-d H:i:s" time.

admin

public function admin()

An admin log entry belongs to an admin user.

Returns \Illuminate\Database\Eloquent\Relations\belongsTo

scopeOnline

public function scopeOnline($query)

Retrieve the most recent open session of every admin user who is online.

Selects one deterministic row per admin user - the highest id - rather than grouping the outer query, which under a permissive sql_mode returns an arbitrary row from each group and under ONLY_FULL_GROUP_BY errors.

The open session constraint is repeated on the outer query deliberately. MySQL materialises this IN rather than rewriting it into a semijoin, so without it the outer query carries no predicate and scans the whole of a table that is never pruned. Repeating it restores an index range scan, and cannot change the result set: every id the subquery yields belongs to a row that already satisfies the constraint.

Parameters

TypeNameDescription
\Illuminate\Database\Eloquent\Builder$query

Returns \Illuminate\Database\Eloquent\Builder

constrainToOpenSessions

public static function constrainToOpenSessions($query)

Narrow a tbladminlog query to the sessions that are still open, meaning visited inside the online window and not yet logged out.

Held here so that the scopes on this model and the staff presence repository agree on the window and on the zero date standing in for "still logged in". It is not the only place that knowledge lives: the legacy admin log screen and the GetStaffOnline and GetStats endpoints still spell the zero date out themselves, in three different literals.

Parameters

TypeNameDescription
\Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder$query

Returns \Illuminate\Database\Query\Builder\|\Illuminate\Database\Eloquent\Builder

scopeOffline

public function scopeOffline($query)

Retrieve the log entries of every admin user who is not currently online.

Parameters

TypeNameDescription
\Illuminate\Database\Eloquent\Builder$query

Returns \Illuminate\Database\Eloquent\Builder

getLastVisitFormattedAttribute

public function getLastVisitFormattedAttribute(): string