You are here

class Database in Audit Log 8

Same name and namespace in other branches
  1. 8.2 src/StorageBackend/Database.php \Drupal\audit_log\StorageBackend\Database

Writes audit events to a custom database table.

@package Drupal\audit_log\StorageBackend

Hierarchy

Expanded class hierarchy of Database

1 string reference to 'Database'
audit_log.services.yml in ./audit_log.services.yml
audit_log.services.yml
1 service uses Database
audit_log.storage_backend.database in ./audit_log.services.yml
Drupal\audit_log\StorageBackend\Database

File

src/StorageBackend/Database.php, line 12

Namespace

Drupal\audit_log\StorageBackend
View source
class Database implements StorageBackendInterface {

  /**
   * {@inheritdoc}
   */
  public function save(AuditLogEventInterface $event) {
    $connection = \Drupal::database();
    $connection
      ->insert('audit_log')
      ->fields([
      'entity_id' => $event
        ->getEntity()
        ->id(),
      'entity_type' => $event
        ->getEntity()
        ->getEntityTypeId(),
      'user_id' => $event
        ->getUser()
        ->id(),
      'event' => $event
        ->getEventType(),
      'previous_state' => $event
        ->getPreviousState(),
      'current_state' => $event
        ->getCurrentState(),
      'message' => $event
        ->getMessage(),
      'variables' => serialize($event
        ->getMessagePlaceholders()),
      'timestamp' => $event
        ->getRequestTime(),
    ])
      ->execute();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Database::save public function Writes the event to the storage backend's storage system. Overrides StorageBackendInterface::save