\Drupal\strata\Capture\EventSubscriber ConfigCaptureSubscriber

Records configuration changes as they are saved.

Config is the realm where a single change does the most damage per byte. Twelve operations a day on a 50,000-user site, under 1% of write volume, and among them are the ones that take a site down: a permission grant, a text format's allowed tags, a mail server, a cache backend. So it is captured in full rather than as a delta - a whole config object is small, and having the complete value means a restore does not depend on replaying every change since the object was created.

A rename is recorded as one operation against the NEW name carrying the old one, plus a delete of the old. Recording only the new name would leave the old object present in every earlier commit with nothing saying it went away, and a restore walking forward would resurrect it.

Summary

Methods
Properties
Constants
__construct
getSubscribedEvents
onSave
onDelete
onRename
No public properties found
No public constants found
No protected methods found
No protected properties found
No protected constants found
isCreate
record
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 subscriber.

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 —

getSubscribedEvents()

getSubscribedEvents() : array<string,mixed>

{@inheritdoc}

Returns

array

Events this subscriber listens to.

onSave()

onSave(\Drupal\Core\Config\ConfigCrudEvent  $event) : void

Records a saved config object.

A save that changed nothing is still recorded. Drupal saves config objects on module install, on import and on form submit whether or not the data moved, and the frame store deduplicates an unchanged value to nothing, so the operation costs its header and buys an accurate record of when the object was last written.

Parameters

\Drupal\Core\Config\ConfigCrudEvent $event

The save event.

Returns

void —

onDelete()

onDelete(\Drupal\Core\Config\ConfigCrudEvent  $event) : void

Records a deleted config object.

Parameters

\Drupal\Core\Config\ConfigCrudEvent $event

The delete event.

Returns

void —

onRename()

onRename(\Drupal\Core\Config\ConfigRenameEvent  $event) : void

Records a renamed config object.

Parameters

\Drupal\Core\Config\ConfigRenameEvent $event

The rename event.

Returns

void —

isCreate()

isCreate(\Drupal\Core\Config\StorableConfigBase  $config) : bool

Whether a save created the object rather than changing it.

Config::isNew() cannot answer this from inside a save subscriber. Config::save() sets the flag to FALSE and only then dispatches, so by the time this runs every save looks like an update. The pre-save data is still intact at that point - it is copied over on the line AFTER the dispatch - so an empty original is what identifies a create.

Parameters

\Drupal\Core\Config\StorableConfigBase $config

The config object being saved.

Returns

bool —

TRUE when the object held nothing before this save.

record()

record(string  $name, \Drupal\strata\Journal\Verb  $verb, array|null  $data, string|null  $from = null) : void

Appends one operation.

Parameters

string $name

The config object name, which is the subject.

\Drupal\strata\Journal\Verb $verb

What happened to it.

array|null $data

The object's data, or NULL for a delete.

string|null $from

The name it was renamed from, or NULL.

Returns

void —

label()

label(string  $name, \Drupal\strata\Journal\Verb  $verb, string|null  $from) : string

The label the timeline shows.

Parameters

string $name

The config object name.

\Drupal\strata\Journal\Verb $verb

What happened to it.

string|null $from

The name it was renamed from, or NULL.

Returns

string —

The label.

actor()

actor() : int|null

The user an operation is attributed to.

Returns

int|null —

A Drupal user id, or NULL for unattended work.

now()

now() : int

The current time in unix microseconds.

Returns

int —

Microseconds since the epoch.