Logging
in package
Uses
BackwardCompatibility
This class concerns itself with logging and tracking statistics.
Honestly, this is just a collection of a few static methods. They're only grouped into a class to take better advantage of namespacing and autoloading.
Table of Contents
Properties
- $backcompat : array<string|int, mixed>
Methods
- displayDebug() : void
- Shows the debug information tracked when Config::$db_show_debug = true.
- exportStatic() : void
- Provides a way to export a class's public static properties and methods to global namespace.
- getMembersOnlineStats() : array<string|int, mixed>
- Retrieve a list and several other statistics of the users currently online.
- logAction() : int
- This function logs an action to the database. It is a thin wrapper around Logging::logActions().
- logActions() : int
- Log changes to the forum, such as moderation events or administrative changes.
- trackStats() : bool
- Track Statistics.
- trackStatsUsersOnline() : mixed
- Check if the number of users online is a record and store it.
- updateStats() : void
- Update some basic statistics.
- writeLog() : void
- Backward compatibility alias for User::$me->logOnline().
Properties
$backcompat
private
static array<string|int, mixed>
$backcompat
= ['func_names' => ['writeLog' => 'writeLog', 'logAction' => 'logAction', 'logActions' => 'logActions', 'updateStats' => 'updateStats', 'trackStats' => 'trackStats', 'trackStatsUsersOnline' => 'trackStatsUsersOnline', 'getMembersOnlineStats' => 'getMembersOnlineStats', 'displayDebug' => 'displayDebug']]
BackwardCompatibility settings for this class.
Methods
displayDebug()
Shows the debug information tracked when Config::$db_show_debug = true.
public
static displayDebug() : void
exportStatic()
Provides a way to export a class's public static properties and methods to global namespace.
public
static exportStatic() : void
To do so:
- Use this trait in the class.
- At the END of the class's file, call its exportStatic() method.
Although it might not seem that way at first glance, this approach conforms to section 2.3 of PSR 1, since executing this method is simply a dynamic means of declaring functions when the file is included; it has no other side effects.
Regarding the $backcompat items:
A class's static properties are not exported to global variables unless explicitly included in $backcompat['prop_names']. Likewise, a class's static methods are not exported as global functions unless explicitly included in $backcompat['func_names'].
$backcompat['prop_names'] is a simple array where the keys are the names of one or more of a class's static properties, and the values are the names of global variables. In each case, the global variable will be set to a reference to the static property. Static properties that are not named in this array will not be exported.
$backcompat['func_names'] is a simple array where the keys are the names of one or more of a class's static methods, and the values are the names that should be used for global functions that will encapsulate those methods. Methods that are not named in this array will not be exported.
Adding non-static properties or methods to the $backcompat arrays will produce runtime errors. It is the responsibility of the developer to make sure not to do this.
getMembersOnlineStats()
Retrieve a list and several other statistics of the users currently online.
public
static getMembersOnlineStats(array<string|int, mixed> $membersOnlineOptions) : array<string|int, mixed>
Used by the board index and SSI. Also returns the membergroups of the users that are currently online. (optionally) hides members that chose to hide their online presence.
Parameters
- $membersOnlineOptions : array<string|int, mixed>
-
An array of options for the list
Return values
array<string|int, mixed> —An array of information about the online users
logAction()
This function logs an action to the database. It is a thin wrapper around Logging::logActions().
public
static logAction(string $action[, array<string|int, mixed> $extra = [] ][, string $log_type = 'moderate' ]) : int
Parameters
- $action : string
-
A code for the report; a list of such strings can be found in Modlog.{language}.php (modlog_ac_ strings)
- $extra : array<string|int, mixed> = []
-
An associated array of parameters for the item being logged. Typically this will include 'topic' for the topic's id.
- $log_type : string = 'moderate'
-
A string reflecting the type of log.
Tags
Return values
int —The ID of the row containing the logged data
logActions()
Log changes to the forum, such as moderation events or administrative changes.
public
static logActions(array<string|int, mixed> $logs) : int
SMF uses three log types:
-
userfor actions executed that aren't related to moderation (e.g. signature or other changes from the profile); -
moderatefor moderation actions (e.g. topic changes); -
adminfor administrative actions.
Parameters
- $logs : array<string|int, mixed>
-
An array of log data
Return values
int —The last logged ID.
trackStats()
Track Statistics.
public
static trackStats([array<string|int, mixed> $stats = [] ]) : bool
Caches statistics changes, and flushes them if you pass nothing. If '+' is used as a value, it will be incremented. It does not actually commit the changes until the end of the page view. It depends on the trackStats setting.
Parameters
- $stats : array<string|int, mixed> = []
-
An array of data
Return values
bool —Whether or not the info was updated successfully
trackStatsUsersOnline()
Check if the number of users online is a record and store it.
public
static trackStatsUsersOnline(int $total_users_online) : mixed
Parameters
- $total_users_online : int
-
The total number of members online
updateStats()
Update some basic statistics.
public
static updateStats(string $type[, mixed $parameter1 = null ][, mixed $parameter2 = null ]) : void
'member' statistic updates the latest member, the total member count, and the number of unapproved members. 'member' also only counts approved members when approval is on, but is much more efficient with it off.
'message' changes the total number of messages, and the highest message id by id_msg - which can be parameters 1 and 2, respectively.
'topic' updates the total number of topics, or if parameter1 is true simply increments them.
'subject' updates the log_search_subjects in the event of a topic being moved, removed or split. parameter1 is the topicid, parameter2 is the new subject
'postgroups' case updates those members who match condition's post-based membergroups in the database (restricted by parameter1).
Parameters
- $type : string
-
Stat type - can be 'member', 'message', 'topic', 'subject' or 'postgroups'
- $parameter1 : mixed = null
-
A parameter for updating the stats
- $parameter2 : mixed = null
-
A 2nd parameter for updating the stats
writeLog()
Backward compatibility alias for User::$me->logOnline().
public
static writeLog([bool $force = false ]) : void
Parameters
- $force : bool = false