Oihana PHP Arango

ArangoReinjectAction uses trait:short, trait:short, trait:short, trait:short, \oihana\commands\traits\IOTrait

The `reinject` action : puts back the documents `preserve` set aside ({@see ArangoPreserveAction}), once a restore has replaced their collection.

For each collection, in one stream transaction :

  1. remove from the collection the documents the rule names — those the restore brought from elsewhere ;
  2. copy the whole backup back ; a duplicate _key is an error, never an overwrite ;
  3. count : the documents the rule now names must be exactly those of the backup — a rule changed since preserve shows here.

Any failure aborts the transaction : the collection is left as it was and the backup is kept. Only a committed transaction drops <collection>__preserved.

🚨 A collection without a backup is left untouched : removing what the rule names with nothing to put back would erase the local documents.

🚨 A rule that names more than its maxPercent of the collection (50 by default) is refused before anything is written — the dry run included — unless --force : a rule meant for the documents of one machine names a small share of a restored collection, and naming most of it says the rule is wrong. --yes skips the confirmation, never this guard. It is checked again in the transaction, on what is actually removed.

It can be run again safely : step 1 removes everything the rule names, a half put back included, before step 2 puts the whole backup back.

Tags
since
1.10.0
author

Marc Alcaraz

Table of Contents

Constants

PARTIAL_MARKER  : string = 'partial'
Marker appended to the archive name when the dump targets a subset of collections (either `--collection` or `--ignore-collection`).

Properties

$dumpConfig  : array<string|int, mixed>
The `[arango.dump]` config defaults (option name => value).
$preserves  : array<string|int, mixed>
The declared rules, from the `[arango.preserves]` config section.
$restoreConfig  : array<string|int, mixed>
The `[arango.restore]` config defaults (option name => value).

Methods

initializeArangoOptions()  : static
Captures the `[arango.dump]` / `[arango.restore]` config sections from the init array. Non-array values are ignored, leaving the defaults empty.
initializeArangoPreserves()  : static
Captures the `[arango.preserves]` config section from the init array.
assertCollectionTargeting()  : void
Asserts that `--collection` and `--ignore-collection` are not used together — `arangodump` rejects that combination.
buildDatabase()  : Database|null
Builds a best-effort {@see Database} HTTP client from the resolved connection settings, or null when no usable endpoint/database is available or the client cannot be constructed.
excludeCollections()  : array<int, string>
Returns the available collection names minus the excluded ones, order-preserving (case-sensitive).
getArchiveNameSuffix()  : string
Builds the archive name suffix (without file extension) shared by the dump output name and the restore-by-date lookup.
isSystemCollection()  : bool
Returns true when the given name is an ArangoDB system collection (its name starts with an underscore, e.g. `_jobs`, `_apps`).
missingCollections()  : array<int, string>
Returns the requested collection names that are NOT present in the available set (case-sensitive, as ArangoDB collection names are).
normalizeCollections()  : array<int, string>
Normalizes a raw collection option into a clean, de-duplicated, order-preserving list of collection names.
preserveCount()  : int
Runs a query that returns a single number, and returns it.
preserveFilters()  : array<string, PreserveFilter>
The compiled rules of the requested collections, keyed and sorted by name.
reinject()  : int
Puts back the documents set aside by `preserve`.
resolveDatabase()  : Database|null
Builds the best-effort {@see Database} HTTP client of an action run: every connection setting reads its CLI option first (`--database` / `--endpoint` / `--user` / `--password`) and falls back on the command configuration ({@see ArangoConfigTrait}).
resolveDumpOptions()  : array<string|int, mixed>
Layers the explicit dump options over the `[arango.dump]` config defaults, then lets the curated CLI flags override everything.
resolveFacade()  : ArangoDB|null
Builds the best-effort high-level {@see ArangoDB} façade of an action run, from the same resolved connection settings as {@see resolveDatabase()} — the migration engine hands this façade to every {@see \oihana\arango\migrations\Migration}. Null when no usable endpoint is configured or the façade cannot be constructed.
resolveRestoreOptions()  : array<string|int, mixed>
Layers the explicit restore options over the `[arango.restore]` config defaults, then lets the curated CLI flags override everything.
restoreProtectedCollections()  : array<int, string>
The collection names the `restore` action refuses to overwrite unless `--force` is passed, read from the `protected` key of the `[arango.restore]` config section ({@see ArangoCommandParam::PROTECTED}).
sanitizeLabel()  : string|null
Validates and normalizes the optional archive label.
preserveFilter()  : PreserveFilter
Validates one `[arango.preserves.<collection>]` rule and compiles it.
putBack()  : array{0: int, 1: int}
Removes from a collection the documents the rule names, then copies its whole backup back — in one transaction.

Constants

PARTIAL_MARKER

Marker appended to the archive name when the dump targets a subset of collections (either `--collection` or `--ignore-collection`).

public string PARTIAL_MARKER = 'partial'

Properties

$dumpConfig

The `[arango.dump]` config defaults (option name => value).

protected array<string|int, mixed> $dumpConfig = []

$preserves

The declared rules, from the `[arango.preserves]` config section.

protected array<string|int, mixed> $preserves = []

$restoreConfig

The `[arango.restore]` config defaults (option name => value).

protected array<string|int, mixed> $restoreConfig = []

Methods

initializeArangoOptions()

Captures the `[arango.dump]` / `[arango.restore]` config sections from the init array. Non-array values are ignored, leaving the defaults empty.

public initializeArangoOptions([array<string|int, mixed> $init = [] ]) : static
Parameters
$init : array<string|int, mixed> = []
Return values
static

initializeArangoPreserves()

Captures the `[arango.preserves]` config section from the init array.

public initializeArangoPreserves([array<string|int, mixed> $init = [] ]) : static
Parameters
$init : array<string|int, mixed> = []
Return values
static

assertCollectionTargeting()

Asserts that `--collection` and `--ignore-collection` are not used together — `arangodump` rejects that combination.

protected static assertCollectionTargeting(array<int, string> $collection, array<int, string> $ignore) : void
Parameters
$collection : array<int, string>
$ignore : array<int, string>
Tags
throws
InvalidArgumentException

When both lists are non-empty.

buildDatabase()

Builds a best-effort {@see Database} HTTP client from the resolved connection settings, or null when no usable endpoint/database is available or the client cannot be constructed.

protected buildDatabase(string $endpoint, string $username, string $password, string $database) : Database|null

No network I/O happens here — the connection is only exercised when a request method (e.g. Database::collections()) is later called by the caller.

Parameters
$endpoint : string

The ArangoDB endpoint (e.g. tcp://127.0.0.1:8529).

$username : string

The connection user.

$password : string

The connection password.

$database : string

The target database name.

Return values
Database|null

excludeCollections()

Returns the available collection names minus the excluded ones, order-preserving (case-sensitive).

protected static excludeCollections(array<int, string> $available, array<int, string> $exclude) : array<int, string>

Used to resolve --ignore-collection client-side: arangodump has no exclusion option, so the complement is computed here and passed back as an explicit --collection list.

Parameters
$available : array<int, string>

The collections that exist.

$exclude : array<int, string>

The collections to drop.

Return values
array<int, string>

getArchiveNameSuffix()

Builds the archive name suffix (without file extension) shared by the dump output name and the restore-by-date lookup.

protected static getArchiveNameSuffix(string $database[, bool $partial = false ][, string|null $label = null ]) : string

Shape: -{database}[-partial][-{label}], e.g.

  • -mydb (full dump)
  • -mydb-partial (targeted dump, no label)
  • -mydb-partial-pre-migration (targeted dump with a label)
Parameters
$database : string

The database name.

$partial : bool = false

Whether the dump targets a subset of collections.

$label : string|null = null

Optional label (validated via sanitizeLabel()).

Tags
throws
InvalidArgumentException

When the label is invalid.

Return values
string

isSystemCollection()

Returns true when the given name is an ArangoDB system collection (its name starts with an underscore, e.g. `_jobs`, `_apps`).

protected static isSystemCollection(string $name) : bool
Parameters
$name : string
Return values
bool

missingCollections()

Returns the requested collection names that are NOT present in the available set (case-sensitive, as ArangoDB collection names are).

protected static missingCollections(array<int, string> $requested, array<int, string> $available) : array<int, string>

Order-preserving and de-duplicated.

Parameters
$requested : array<int, string>

The collections asked for on the CLI.

$available : array<int, string>

The collections that actually exist.

Return values
array<int, string> —

The unknown collection names (empty when all exist).

normalizeCollections()

Normalizes a raw collection option into a clean, de-duplicated, order-preserving list of collection names.

protected static normalizeCollections(array<int|string, mixed> $raw) : array<int, string>

Accepts both syntaxes (and any mix):

  • repeated flags : ['users', 'products']
  • comma-separated : ['users,products']
  • mixed/with spaces : [' users , products ', 'customers']

Empty fragments are dropped; the first occurrence order is kept.

Parameters
$raw : array<int|string, mixed>
Return values
array<int, string>

preserveCount()

Runs a query that returns a single number, and returns it.

protected preserveCount(Database $db, AqlQuery $query) : int
Parameters
$db : Database

The database to query.

$query : AqlQuery

A query returning one integer.

Return values
int

preserveFilters()

The compiled rules of the requested collections, keyed and sorted by name.

protected preserveFilters([array<int, string> $only = [] ]) : array<string, PreserveFilter>
Parameters
$only : array<int, string> = []

The collections named on the command line ; empty means every declared rule.

Tags
throws
InvalidArgumentException

When no rule is declared, a named collection has no rule, or a rule cannot be read.

Return values
array<string, PreserveFilter>

reinject()

Puts back the documents set aside by `preserve`.

protected reinject(InputInterface $input, OutputInterface $output) : int
Parameters
$input : InputInterface
$output : OutputInterface
Tags
throws
Throwable

When a put back fails — its transaction is aborted and the backup kept.

Return values
int

resolveDatabase()

Builds the best-effort {@see Database} HTTP client of an action run: every connection setting reads its CLI option first (`--database` / `--endpoint` / `--user` / `--password`) and falls back on the command configuration ({@see ArangoConfigTrait}).

protected resolveDatabase(InputInterface $input) : Database|null

One-stop shop for the actions — see buildDatabase() for the null-on-failure semantics.

Parameters
$input : InputInterface

The action input carrying the optional CLI overrides.

Return values
Database|null

resolveDumpOptions()

Layers the explicit dump options over the `[arango.dump]` config defaults, then lets the curated CLI flags override everything.

protected resolveDumpOptions(array<string|int, mixed> $explicit, InputInterface $input) : array<string|int, mixed>
Parameters
$explicit : array<string|int, mixed>

The options resolved by the action (connection, output directory, collection targeting).

$input : InputInterface

The current console input.

Return values
array<string|int, mixed>

resolveFacade()

Builds the best-effort high-level {@see ArangoDB} façade of an action run, from the same resolved connection settings as {@see resolveDatabase()} — the migration engine hands this façade to every {@see \oihana\arango\migrations\Migration}. Null when no usable endpoint is configured or the façade cannot be constructed.

protected resolveFacade(InputInterface $input) : ArangoDB|null
Parameters
$input : InputInterface

The action input carrying the optional CLI overrides.

Return values
ArangoDB|null

resolveRestoreOptions()

Layers the explicit restore options over the `[arango.restore]` config defaults, then lets the curated CLI flags override everything.

protected resolveRestoreOptions(array<string|int, mixed> $explicit, InputInterface $input) : array<string|int, mixed>
Parameters
$explicit : array<string|int, mixed>

The options resolved by the action (connection, input directory, create flags, collection targeting).

$input : InputInterface

The current console input.

Return values
array<string|int, mixed>

restoreProtectedCollections()

The collection names the `restore` action refuses to overwrite unless `--force` is passed, read from the `protected` key of the `[arango.restore]` config section ({@see ArangoCommandParam::PROTECTED}).

protected restoreProtectedCollections() : array<int, string>

Non-array values and non-string entries are ignored.

Return values
array<int, string>

sanitizeLabel()

Validates and normalizes the optional archive label.

protected static sanitizeLabel(string|null $label) : string|null

Returns null for a null/empty value. Otherwise the label must only contain letters, digits, dot, underscore and hyphen so it stays safe inside a filename.

Parameters
$label : string|null
Tags
throws
InvalidArgumentException

When the label contains unsafe characters.

Return values
string|null

preserveFilter()

Validates one `[arango.preserves.<collection>]` rule and compiles it.

private preserveFilter(string $collection, mixed $definition) : PreserveFilter
Parameters
$collection : string

The collection the rule is declared for.

$definition : mixed

The rule as the configuration gives it.

Tags
throws
InvalidArgumentException

When the rule cannot be read.

Return values
PreserveFilter

putBack()

Removes from a collection the documents the rule names, then copies its whole backup back — in one transaction.

private putBack(Database $db, PreserveFilter $filter, bool $forced) : array{0: int, 1: int}

The share guard is checked again on what is actually removed, so a write between the summary and the transaction cannot slip a rule past it.

Parameters
$db : Database
$filter : PreserveFilter
$forced : bool

True when --force lets a rule name more than its maxPercent.

Tags
throws
Throwable

When a step fails or the counts disagree — the transaction is aborted.

Return values
array{0: int, 1: int} —

The number of documents removed, then put back.

On this page

Search results