function event_log_track_insert in Events Log Track 8.2
Same name and namespace in other branches
- 8 event_log_track.module \event_log_track_insert()
Inserts the log record in the event log track. Sets the lid.
Parameters
array $log: The log record to be saved. This record contains the following fields:
- {string} type The event type. This is usually the object type that is described by this event. Example: 'node' or 'user'. Required.
- {string} operation The operation being performed. Example: 'insert'. Required.
- {string} description A textual description of the event. Required.
- {string} ref_numeric Reference to numeric id. Optional.
- {string} ref_char Reference to alphabetical id. Optional.
26 calls to event_log_track_insert()
- event_log_track_auth_user_login_validate in event_log_track_auth/
event_log_track_auth.module - Implements hook_form_FORM_ID_validate().
- event_log_track_auth_user_logout in event_log_track_auth/
event_log_track_auth.module - Implements hook_user_logout().
- event_log_track_file_delete in event_log_track_file/
event_log_track_file.module - Implements hook_ENTITY_TYPE_delete().
- event_log_track_file_insert in event_log_track_file/
event_log_track_file.module - Implements hook_ENTITY_TYPE_insert().
- event_log_track_file_update in event_log_track_file/
event_log_track_file.module - Implements hook_ENTITY_TYPE_update().
File
- ./
event_log_track.module, line 64 - Track the logs of form submissions or other actions that performed by user.
Code
function event_log_track_insert(array &$log) {
if (PHP_SAPI == 'cli') {
// Ignore CLI requests.
return;
}
if (empty($log['created'])) {
$log['created'] = \Drupal::time()
->getRequestTime();
}
if (empty($log['uid'])) {
$account = \Drupal::currentUser();
$log['uid'] = $account
->id();
}
$ip = Drupal::request()
->getClientIp();
if (empty($log['ip']) && !empty($ip)) {
$log['ip'] = $ip;
}
if (empty($log['path'])) {
$log['path'] = Url::fromRoute('<current>')
->getInternalPath();
}
if (empty($log['ref_numeric'])) {
$log['ref_numeric'] = NULL;
}
\Drupal::database()
->merge('event_log_track')
->key('lid')
->fields([
'type' => $log['type'],
'operation' => $log['operation'],
'description' => $log['description'],
'created' => $log['created'],
'uid' => $log['uid'],
'ip' => $log['ip'],
'path' => $log['path'],
'ref_char' => $log['ref_char'],
'ref_numeric' => $log['ref_numeric'],
])
->execute();
}