\Drupal\strata\Hook EntityCapture

Records entity creates, updates and deletes as they happen.

The three hooks fire after the entity storage has committed, so what is captured is what the site now holds rather than what a save intended. The previous version comes from the entity's own original, which is already in memory, so an update costs a comparison rather than a second read.

A capture never breaks a save. Everything here runs inside someone's request, and a backup that takes the site down when its bucket is unreachable is worse than a missing backup, so every hook catches, records a finding, and returns. The reconciler notices the gap on the next pass.

Summary

Methods
Properties
Constants
__construct
onInsert
onUpdate
onDelete
No public properties found
No public constants found
No protected methods found
No protected properties found
No protected constants found
capture
appendLoginEvent
subject
label
actor
now
journal
scope
currentUser
logger
requestId
No private constants found

Properties

$journal

$journal : \Drupal\strata\Journal\JournalInterface

Type

JournalInterface

$scope

$scope : \Drupal\strata\Capture\CaptureScope

Type

CaptureScope

$currentUser

$currentUser : \Drupal\Core\Session\AccountProxyInterface

Type

AccountProxyInterface

$logger

$logger : \Psr\Log\LoggerInterface

Type

LoggerInterface

$requestId

$requestId : string

Type

string

Methods

__construct()

__construct(\Drupal\strata\Journal\JournalInterface  $journal, \Drupal\strata\Capture\CaptureScope  $scope, \Drupal\Core\Session\AccountProxyInterface  $currentUser, \Psr\Log\LoggerInterface  $logger, string  $requestId = '') : mixed

Constructs the capture.

Parameters

\Drupal\strata\Journal\JournalInterface $journal

Where operations are appended.

\Drupal\strata\Capture\CaptureScope $scope

Decides what is captured.

\Drupal\Core\Session\AccountProxyInterface $currentUser

Attributes an operation to whoever caused it.

\Psr\Log\LoggerInterface $logger

Records a capture that failed.

string $requestId

Groups every operation captured in one request.

Returns

mixed —

onInsert()

onInsert(\Drupal\Core\Entity\EntityInterface  $entity) : void

Records a newly created entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity

The entity that was created.

Returns

void —

onUpdate()

onUpdate(\Drupal\Core\Entity\EntityInterface  $entity) : void

Records a changed entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity

The entity that was saved.

Returns

void —

onDelete()

onDelete(\Drupal\Core\Entity\EntityInterface  $entity) : void

Records a removed entity.

A delete carries no payload: the value is whatever the previous commit already holds, and a restore reaches it by walking back rather than by reading it here.

Parameters

\Drupal\Core\Entity\EntityInterface $entity

The entity that was deleted.

Returns

void —

capture()

capture(\Drupal\Core\Entity\EntityInterface  $entity, \Drupal\strata\Journal\Verb  $verb, \Drupal\Core\Entity\EntityInterface|null  $original) : void

Appends one entity operation.

Parameters

\Drupal\Core\Entity\EntityInterface $entity

The entity.

\Drupal\strata\Journal\Verb $verb

What happened to it.

\Drupal\Core\Entity\EntityInterface|null $original

The previous version, for an update.

Returns

void —

appendLoginEvent()

appendLoginEvent(\Drupal\Core\Entity\EntityInterface  $entity) : void

Appends a compact login event instead of a full field delta.

Access-timestamp churn is two thirds of a Drupal site's write volume and restoring an old value would misreport an active account as dormant. The event keeps the security trail - who was seen, and when - at a fraction of the size, and carries no payload to restore.

Parameters

\Drupal\Core\Entity\EntityInterface $entity

The user whose access timestamps moved.

Returns

void —

subject()

subject(\Drupal\Core\Entity\EntityInterface  $entity) : string

The subject key an entity is recorded under.

Parameters

\Drupal\Core\Entity\EntityInterface $entity

The entity.

Returns

string —

Something such as "node:42".

label()

label(\Drupal\Core\Entity\EntityInterface  $entity, \Drupal\strata\Journal\Verb  $verb) : string

The human label recorded with an operation.

Parameters

\Drupal\Core\Entity\EntityInterface $entity

The entity.

\Drupal\strata\Journal\Verb $verb

What happened to it.

Returns

string —

A label for the timeline.

actor()

actor() : int|null

The user an operation is attributed to.

Returns

int|null —

A Drupal user id, or NULL for anonymous and unattended work.

now()

now() : int

The current time in unix microseconds.

Returns

int —

Microseconds since the epoch.