\Drupal\strata\Drush\Commands StrataCommands

The commands an operator runs on a working site.

Reading is separated from writing here. strata:status, strata:list and strata:sites answer questions and are safe on any site in any state, so each of them reports a misconfigured store as a field rather than as an exception: an operator asking why backups are not running needs the answer printed, not a stack trace. strata:snapshot and strata:flush seal history and fail loudly, because a flush that quietly did nothing is the failure this module exists to prevent.

Every table is returned as structured data rather than printed, so --format=json and --field work on all of them without a second code path.

Summary

Methods
Properties
Constants
__construct
status
commits
sites
snapshot
flush
No public properties found
No public constants found
value
number
flag
ref
prose
agreed
announce
bytes
moment
digest
duration
yesNo
No protected properties found
No protected constants found
storeState
lag
flushDue
budget
siteIds
headOf
micro
engine
configFactory
commits
journal
frames
ledger
No private constants found

Properties

$engine

$engine : \Drupal\strata\Engine

Type

Engine

$configFactory

$configFactory : \Drupal\Core\Config\ConfigFactoryInterface

Type

ConfigFactoryInterface

$commits

$commits : \Drupal\strata\Tree\CommitIndex

Type

CommitIndex

$journal

$journal : \Drupal\strata\Journal\JournalInterface

Type

JournalInterface

Methods

__construct()

__construct(\Drupal\strata\Engine  $engine, \Drupal\Core\Config\ConfigFactoryInterface  $configFactory, \Drupal\strata\Tree\CommitIndex  $commits, \Drupal\strata\Journal\JournalInterface  $journal, \Drupal\strata\Cas\FrameIndexInterface  $frames, \Drupal\strata\Health\HealthLedgerInterface  $ledger) : mixed

Constructs the command set.

Parameters

\Drupal\strata\Engine $engine

Builds the pipeline this site is configured for.

\Drupal\Core\Config\ConfigFactoryInterface $configFactory

Read for the settings a status report names.

\Drupal\strata\Tree\CommitIndex $commits

The local index history is listed from, which costs no requests.

\Drupal\strata\Journal\JournalInterface $journal

Asked what has been captured but not yet sealed.

\Drupal\strata\Cas\FrameIndexInterface $frames

Asked what the store holds.

\Drupal\strata\Health\HealthLedgerInterface $ledger

Asked how many findings are outstanding.

Returns

mixed —

status()

status() : \Consolidation\OutputFormatters\StructuredData\PropertyList

What Strata is doing on this site, and what it cannot do.

Returns

\Consolidation\OutputFormatters\StructuredData\PropertyList —

One row per fact.

commits()

commits(array  $options = ['limit' => 50, 'level' => \self::REQ, 'since' => \self::REQ, 'until' => \self::REQ]) : \Consolidation\OutputFormatters\StructuredData\RowsOfFields

The commits this site's history holds, newest first.

Parameters

array $options

Command options.

Returns

\Consolidation\OutputFormatters\StructuredData\RowsOfFields —

One row per commit, empty when nothing has been sealed yet.

sites()

sites() : \Consolidation\OutputFormatters\StructuredData\RowsOfFields

Which sites share this bucket.

Frames are shared across sites and history is not, so the prefixes that are neither content nor this site are other sites' histories. Listing them is how an operator confirms that a bucket holds what they think it holds before pointing a restore at it.

Returns

\Consolidation\OutputFormatters\StructuredData\RowsOfFields —

One row per site, empty when the store has never been written to.

snapshot()

snapshot(array  $options = ['skip-reconcile' => false, 'skip-code' => false, 'tables' => 100, 'ref' => \Drupal\strata\Tree\RefStore::MAIN]) : \Consolidation\OutputFormatters\StructuredData\RowsOfFields

Captures everything no hook observes, then seals a commit covering all of it.

Entity, config and state writes arrive through hooks as they happen. Table drift and code changes do not, so a commit sealed without them describes only part of the site. This runs those passes first and forces the flush afterwards, which makes the resulting commit a complete point in time rather than whatever the hooks happened to see.

Parameters

array $options

Command options.

Returns

\Consolidation\OutputFormatters\StructuredData\RowsOfFields —

One row per stage.

flush()

flush(array  $options = ['ref' => \Drupal\strata\Tree\RefStore::MAIN, 'if-due' => false]) : \Consolidation\OutputFormatters\StructuredData\PropertyList

Seals whatever has been captured but not yet stored.

Parameters

array $options

Command options.

Returns

\Consolidation\OutputFormatters\StructuredData\PropertyList —

What the flush did.

value()

value(array  $options, string  $name) : string|null

Reads an option that carries a value.

A value option declares DrushCommands::REQ as its default, and Drush replaces that with the string the operator supplied or with NULL before the command body runs. A method called directly - from a test, a hook, or another command - still sees the sentinel, and both forms mean that nothing was supplied. Drush only ever passes a string, so an integer sentinel cannot be confused with a value.

Parameters

array $options

The options the command was called with.

string $name

The option name.

Returns

string|null —

The value, or NULL when none was supplied.

number()

number(array  $options, string  $name, int  $fallback) : int

Reads an option that carries a whole number.

Parameters

array $options

The options the command was called with.

string $name

The option name.

int $fallback

What to return when nothing was supplied.

Returns

int —

The value, or the fallback.

flag()

flag(array  $options, string  $name) : bool

Whether a flag was given.

Parameters

array $options

The options the command was called with.

string $name

The option name.

Returns

bool —

TRUE when the flag was supplied.

ref()

ref(array  $options) : string

The ref an option set names.

Parameters

array $options

The options the command was called with.

Returns

string —

The ref name, or the main ref when none was supplied.

prose()

prose() : \Symfony\Component\Console\Style\SymfonyStyle

The style prose is written to.

Returns

\Symfony\Component\Console\Style\SymfonyStyle —

A style over standard error.

agreed()

agreed(string  $question) : bool

Asks before doing something that removes a restore target or overwrites live data.

Drush answers this itself under --yes and --no, so a scripted run never blocks. The default is no, because the question is only ever asked about something irreversible.

Parameters

string $question

What is about to happen, phrased as a question.

Returns

bool —

TRUE to go ahead.

announce()

announce(bool  $acted, string  $summary) : void

States what a pass did, at the severity the outcome deserves.

A pass that ran and a pass that declined to run both produce a summary worth reading, and the difference between them is what an operator watching a scheduled job needs to see.

Parameters

bool $acted

TRUE when the pass did the thing it was asked to do.

string $summary

The one-line summary to print.

Returns

void —

bytes()

bytes(int  $bytes) : string

Renders a byte count at a readable scale.

Parameters

int $bytes

The count.

Returns

string —

For example "4.0 MiB".

moment()

moment(int  $microtime) : string

Renders unix microseconds as a timestamp.

Parameters

int $microtime

Microseconds since the epoch, or zero for no moment at all.

Returns

string —

An ISO-8601 timestamp, or "-".

digest()

digest(string|null  $digest) : string

Shortens a content address for a table cell.

Anything that is not a digest is returned whole, so an object key or a refusal reason passed here is readable rather than truncated to twelve characters of a path.

Parameters

string|null $digest

The digest, or NULL.

Returns

string —

The first twelve characters of a digest, the value unchanged when it is not one, or "-".

duration()

duration(float  $seconds) : string

Renders a duration.

Parameters

float $seconds

The duration.

Returns

string —

For example "1.24s".

yesNo()

yesNo(bool  $value) : string

Renders a boolean as a word.

Parameters

bool $value

The value.

Returns

string —

Either "yes" or "no".

storeState()

storeState() : string

Whether the configured store can be reached, or why it cannot.

Returns

string —

Either "reachable" or a sentence naming the obstacle.

lag()

lag() : float

How far behind the store is, in seconds.

Read from the journal rather than from the flusher, so a store that cannot be constructed still reports its lag.

Returns

float —

Seconds since the oldest unsealed operation, or zero when nothing is pending.

flushDue()

flushDue() : string

Whether the flush policy says a window is due.

Returns

string —

Either "yes", "no", or the reason the question could not be answered.

budget()

budget() : string

Where the month sits against whichever ceiling is configured.

Returns

string —

The rung and the fraction used, or a note that no ceiling is set.

siteIds()

siteIds(\Drupal\strata\Storage\StorageProviderInterface  $bucket) : list<string>

Every site id present in a bucket.

Parameters

\Drupal\strata\Storage\StorageProviderInterface $bucket

The unscoped provider.

Returns

list

Site ids, in listing order.

headOf()

headOf(\Drupal\strata\Storage\StorageProviderInterface  $bucket, string  $id) : string|null

The commit one site's main ref points at.

Parameters

\Drupal\strata\Storage\StorageProviderInterface $bucket

The unscoped provider.

string $id

The site id.

Returns

string|null —

The commit id, or NULL when the site has no main ref or it cannot be read.

micro()

micro(string|null  $expression, int  $fallback) : int

Turns a time expression into unix microseconds.

Parameters

string|null $expression

Anything strtotime reads, or NULL.

int $fallback

What to return when there is nothing to parse.

Returns

int —

Microseconds since the epoch.