You are here

function event_log_track_insert in Events Log Track 8

Same name and namespace in other branches
  1. 8.2 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.
18 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_form_submit in ./event_log_track.module
Form submission callback.
event_log_track_menu_menu_delete in event_log_track_menu/event_log_track_menu.module
Implements hook_menu_delete().
event_log_track_menu_menu_insert in event_log_track_menu/event_log_track_menu.module
Implements hook_menu_insert().

... See full list

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'] = REQUEST_TIME;
  }
  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(array(
    '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();
}