You are here

function audit_log in Audit Log 7

Log an audit log.

Parameters

mixed $entity: The entity on which the action is performed.

string $entity_type: The entity type of the entity on which the action is performed.

string $action: The action that was performed ('view', 'insert', 'update' or 'delete).

object $account: The user that performed the action.

string $url: The url on which the action was performed.

int $timestamp: The timestamp when the action was performed.

array $params: Optional array to pass extra parameters.

See also

hook_audit_log_alter()

hook_audit_log()

AuditLog::log()

hook_audit_log_insert()

14 calls to audit_log()
audit_log_entity_delete in ./audit_log.module
Implements hook_entity_delete().
audit_log_entity_insert in ./audit_log.module
Implements hook_entity_insert().
audit_log_entity_update in ./audit_log.module
Implements hook_entity_update().
audit_log_entity_view in ./audit_log.module
Implements hook_entity_view().
audit_log_hybridauth_hybridauth_identity_added in modules/audit_log_hybridauth/audit_log_hybridauth.module
Implements hook_hybridauth_identity_added().

... See full list

7 string references to 'audit_log'
audit_log_db_audit_log in modules/audit_log_db/audit_log_db.module
Implements hook_audit_log().
audit_log_db_schema in modules/audit_log_db/audit_log_db.install
Implements hook_schema().
audit_log_db_update_7001 in modules/audit_log_db/audit_log_db.install
Add message to audit_log table.
audit_log_db_views_data_alter in modules/audit_log_db/views/audit_log_db.views.inc
Implements hook_views_data_alter().
audit_log_db_views_default_views in modules/audit_log_db/views/audit_log_db.views_default.inc
Implements hook_views_default_views()

... See full list

File

./audit_log.module, line 33
Hook implemenations for the Audit log module.

Code

function audit_log($entity, $entity_type, $action = 'view', $account = NULL, $url = NULL, $timestamp = REQUEST_TIME, $params = array()) {
  list($id, , $bundle) = entity_extract_ids($entity_type, $entity);
  if (!$account) {
    global $user;
    $account = $user;
  }
  if (!$url) {
    $url = request_path();
  }
  $values = array(
    'entity_id' => $id,
    'entity_type' => $entity_type,
    'entity_label' => entity_label($entity_type, $entity),
    'bundle' => $bundle,
    'uid' => $account ? $account->uid : NULL,
    'url' => $url,
    'timestamp' => $timestamp,
    'audit_action' => $action,
  );
  if (isset($params) && is_array($params)) {
    foreach ($params as $property => $param) {
      $values[$property] = $param;
    }
  }
  $log = new Auditlog(array_filter($values));
  $context = array(
    'entity' => $entity,
    'entity_type' => $entity_type,
    'action' => $action,
    'account' => $account,
    'url' => $url,
    'timestamp' => $timestamp,
  );

  // Does this need to be logged.
  $log_it = module_invoke_all('audit_log_it', $log, $context, $account);
  if (in_array(AUDIT_LOG_DO_NOT_LOG, $log_it, TRUE)) {

    // Inform other modules it has not been logged.
    module_invoke_all('audit_log_skipped', $log);
    return;
  }

  // Allow other modules to alter the log object.
  drupal_alter('audit_log', $log, $context);

  // Log the object.
  $log
    ->log();

  // Inform other modules it has been logged.
  module_invoke_all('audit_log_insert', $log);
}