Oihana PHP Arango

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

The `preserve` action : sets aside, in a backup collection, the local documents a `[arango.preserves]` rule names — before a restore replaces their collection.

reinject puts them back afterwards (ArangoReinjectAction).

For each collection, the backup is <collection>__preserved, created with the type of the collection (an edge collection for edges, so _from and _to survive). The copy and its counts run in one stream transaction : the number copied, the number the rule names and the number in the backup must agree, or nothing is set aside and the backup is dropped.

Everything is checked before anything is written. A backup that already exists is refused : it holds documents a previous preserve set aside and no reinject has put back yet — overwriting it would lose them.

It talks to ArangoDB over HTTP only : unlike dump / restore, it needs no arangodump / arangorestore binary.

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

$preserves  : array<string|int, mixed>
The declared rules, from the `[arango.preserves]` config section.

Methods

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.
preserve()  : int
Sets aside the local documents named by the `[arango.preserves]` rules.
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.
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}).
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.
sanitizeLabel()  : string|null
Validates and normalizes the optional archive label.
preserveFilter()  : PreserveFilter
Validates one `[arango.preserves.<collection>]` rule and compiles it.
setAside()  : int
Creates the backup of a collection and copies into it the documents the rule names.

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

$preserves

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

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

Methods

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>

preserve()

Sets aside the local documents named by the `[arango.preserves]` rules.

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

When a copy fails — the backup of that collection is dropped first.

Return values
int

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>

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

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

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

setAside()

Creates the backup of a collection and copies into it the documents the rule names.

private setAside(Database $db, PreserveFilter $filter) : int
Parameters
$db : Database
$filter : PreserveFilter
Tags
throws
Throwable

When the copy fails or its counts disagree — the backup is dropped first.

Return values
int —

The number of documents set aside.

On this page

Search results