Oihana PHP Arango

ArangoActions uses trait:short, trait:short, trait:short, trait:short, trait:short, trait:short, trait:short, trait:short

The ArangoDB CLI subcommands database.

Table of Contents

Constants

ARCHIVE_REGEXP  : string = \oihana\arango\commands\enums\ArchivePattern::R...
The pattern to find the archive files.
COMPLETE_SYSTEM_COLLECTIONS  : array<string|int, mixed> = ['_analyzers', '_graphs']
The system collections added by a `--complete` backup (the custom analyzers and the named graph definitions).

Properties

$compression  : string|null
The compression of the dump file.
$exit  : string
The exit message.

Methods

dump()  : int
Dump the ArangoDB database.
restore()  : int
Restore the ArangoDB database.
analyzers()  : int
Manages the custom analyzers of the database.
collections()  : int
Lists the collections of the database.
doctor()  : int
Diagnoses (or repairs) the declared structure of the database.
getArchiveFileSuffix()  : string
Builds the archive file name suffix used to locate a dump by date.
listDumps()  : int
List the dump files of the database.
migrate()  : int
Applies / inspects / rolls back the data migrations.
views()  : int
Manages the views of the database.
analyzersFix()  : int
Generates one ready-to-review **repair migration** per drifted analyzer — the deferred, versioned form of the `--sync --force` cascade. It writes files only and **never** touches the database.
analyzersList()  : int
Lists the custom analyzers of the database (built-in ones summarized as a count, since they are always present and not managed here).
analyzersPrune()  : int
Drops the **orphan** custom analyzers — on the server, declared by none — after confirmation (the opt-in `--prune` mode).
analyzersRenderOrphans()  : void
Prints the orphan custom analyzers — on the server but declared by none.
analyzersRenderReport()  : void
Prints one analyzer's {@see DiffReport} as a status line plus one indented line per change.
analyzersRepairBody()  : string
Builds the `up()` body of a repair migration for one drifted analyzer: the declared `type` + `properties` are dumped as a flat PHP literal (via {@see toPhpString()}) into a {@see RawAnalyzer}, wrapped in an {@see AnalyzerDefinition} and forced through `analyzerSync()` (path B — same-name drop + recreate + dependent-View rebuild).
analyzersReport()  : int
Walks the declared analyzers and reports (or provisions, in apply mode) their state, with the orphan custom analyzers as a footnote.
analyzersShortName()  : string
Strips the `dbname::` namespace prefix from an analyzer name.
archiveCollections()  : array<int, string>
The collection names declared by the `*.structure.json` files of an untarred dump — the universe used by an exclude-only profile on restore.
buildRunner()  : MigrationRunner|null
Builds the migration runner from the resolved façade and the command configuration, or null (with an error printed) when no database or no migrations path is available.
doctorAccount()  : void
Accounts one diff report into the running doctor state: renders it, bumps the status counter, flips the health flag when the report is not in sync (and was not freshly applied), and collects it when applied. Shared by the model walk and the collection-index registry walk.
doctorJournal()  : void
Journals each applied object as a `CreateAction` in the tracking collection — the audit trail of `doctor --apply`, told apart from the versioned migrations by its `additionalType` ({@see MigrationKind::DOCTOR}).
doctorOrphans()  : array<int, string>
Computes and prints the orphans — collections (non-system) and views on the server that no configured model declares. Report only.
doctorPrune()  : void
Offers the interactive multi-selection of the orphans to remove and drops the chosen ones. Nothing happens in non-interactive mode.
doctorRenderReport()  : void
Prints one {@see DiffReport} as a status line (labelled with its {@see DiffKind}) plus one indented line per change.
dumpAvailableCollections()  : array<int, string>
Returns the user (non-system) collection names of the live database, or throws when the HTTP API is unavailable — used by the exclusion paths (`--ignore-collection` and exclude-only profiles) that need the universe.
dumpCompleteCollections()  : array<int, string>
Returns the collection list of a `--complete` backup: every user collection plus the {@see COMPLETE_SYSTEM_COLLECTIONS} that exist on the server. Throws when the HTTP API is unavailable.
isLocalEndpoint()  : bool
True when an ArangoDB endpoint targets the local machine.
migrateApply()  : int
Applies the pending migrations, after confirmation.
migrateCreate()  : int
Generates an empty migration shell.
migrateDown()  : int
Rolls back the last `$count` applied migrations.
migrateDryRun()  : int
Lists the pending migrations without running them.
migrateStatus()  : int
Prints the applied / pending status table.
restoreSelectionLabel()  : string
A human-readable description of the restore selection, for `--dry-run` (the exact exclude-only list is only known once the archive is untarred).
viewsDatabase()  : Database|null
Builds the live {@see Database} client from the command options/configuration, or null (with an error printed) when no usable endpoint is available.
viewsDrop()  : int
Drops the given views (comma-separated), or offers an interactive selection across the views of the database.
viewsList()  : int
Lists the views of the database (name, type, linked collections).
viewsRenderOrphans()  : void
Prints the orphan views — on the server but declared by none of the configured models. Report only : orphans are never dropped here, use `--drop` explicitly.
viewsRenderReport()  : void
Prints one model's {@see DiffReport} as a status line plus one indented line per change.
viewsReport()  : int
Walks the configured models and reports (or repairs, in apply mode) the state of their declared views, with the orphan views of the database as a footnote.
viewsReportSearchAliases()  : int
Reconciles the database-level `search-alias` view registry (the `searchAliasViews` init key) — the federated counterpart of the model-driven loop. Declared names are appended to `$declared` so they are not later flagged as orphans.

Constants

ARCHIVE_REGEXP

The pattern to find the archive files.

public string ARCHIVE_REGEXP = \oihana\arango\commands\enums\ArchivePattern::REGEXP

COMPLETE_SYSTEM_COLLECTIONS

The system collections added by a `--complete` backup (the custom analyzers and the named graph definitions).

private array<string|int, mixed> COMPLETE_SYSTEM_COLLECTIONS = ['_analyzers', '_graphs']

Properties

$compression

The compression of the dump file.

public string|null $compression = \oihana\files\enums\CompressionType::GZIP

Methods

dump()

Dump the ArangoDB database.

public dump(InputInterface $input, OutputInterface $output) : int
Parameters
$input : InputInterface
$output : OutputInterface
Tags
throws
DateInvalidOperationException
DirectoryException
FileException
MissingPassphraseException
RandomException
ReflectionException
UnsupportedCompressionException
Return values
int

restore()

Restore the ArangoDB database.

public restore(InputInterface $input, OutputInterface $output) : int
Parameters
$input : InputInterface
$output : OutputInterface
Tags
throws
DirectoryException
ExitException
FileException
MissingPassphraseException
Return values
int

analyzers()

Manages the custom analyzers of the database.

protected analyzers(InputInterface $input, OutputInterface $output) : int
Parameters
$input : InputInterface
$output : OutputInterface
Return values
int

collections()

Lists the collections of the database.

protected collections(InputInterface $input, OutputInterface $output) : int
Parameters
$input : InputInterface
$output : OutputInterface
Return values
int

doctor()

Diagnoses (or repairs) the declared structure of the database.

protected doctor(InputInterface $input, OutputInterface $output) : int
Parameters
$input : InputInterface
$output : OutputInterface
Tags
throws
ExitException

When the interactive prune selection is exited.

ReflectionException
Return values
int

getArchiveFileSuffix()

Builds the archive file name suffix used to locate a dump by date.

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

The dump action always produces a gzip-compressed tarball ({date}-{database}[-partial][-{label}].tar.gz), optionally AES-encrypted (….tar.gz.enc). This helper mirrors that naming so a targeted dump can be located by --date (the caller must pass the same --collection/--ignore-collection and --label it dumped with). The name part is delegated to getArchiveNameSuffix().

Parameters
$database : string

The database name embedded in the suffix.

$encrypt : bool = false

Whether the archive is encrypted.

$partial : bool = false

Whether the dump targets a subset of collections.

$label : string|null = null

Optional label appended to the name.

Return values
string

e.g. -mydb.tar.gz, -mydb-partial.tar.gz or -mydb-partial-pre-migration.tar.gz.enc.

listDumps()

List the dump files of the database.

protected listDumps(InputInterface $input, OutputInterface $output[, string|null $directory = null ]) : int

The listed directory follows the same precedence as the dump and the prune: the --directory CLI flag wins, then the optional $directory (e.g. a profile output directory resolved by the caller), then the global $this->directory.

Parameters
$input : InputInterface
$output : OutputInterface
$directory : string|null = null

An optional directory override (the profile output directory), below the --directory CLI flag and above the global directory.

Tags
throws
DirectoryException
Return values
int

migrate()

Applies / inspects / rolls back the data migrations.

protected migrate(InputInterface $input, OutputInterface $output) : int
Parameters
$input : InputInterface
$output : OutputInterface
Return values
int

views()

Manages the views of the database.

protected views(InputInterface $input, OutputInterface $output) : int
Parameters
$input : InputInterface
$output : OutputInterface
Tags
throws
ExitException

When the interactive selection is exited.

Return values
int

analyzersFix()

Generates one ready-to-review **repair migration** per drifted analyzer — the deferred, versioned form of the `--sync --force` cascade. It writes files only and **never** touches the database.

private analyzersFix(InputInterface $input, SymfonyStyle $io) : int

Each drifted AnalyzerDefinition yields a Version*.php migration whose up() reconstructs the declared analyzer with a RawAnalyzer (the declared type + properties dumped as a flat literal) and calls analyzerSync( $def , force: true ) — the same-name drop + recreate + dependent-View rebuild (path B). The rollback is left as a comment: a repair is not auto-reversible (re-applying the previous analyzer would re-introduce the drift). Review the files, then run migrate.

Parameters
$input : InputInterface
$io : SymfonyStyle
Return values
int

analyzersList()

Lists the custom analyzers of the database (built-in ones summarized as a count, since they are always present and not managed here).

private analyzersList(InputInterface $input, SymfonyStyle $io) : int
Parameters
$input : InputInterface
$io : SymfonyStyle
Return values
int

analyzersPrune()

Drops the **orphan** custom analyzers — on the server, declared by none — after confirmation (the opt-in `--prune` mode).

private analyzersPrune(InputInterface $input, OutputInterface $output, SymfonyStyle $io) : int

Only custom analyzers (named dbname::…) are considered: built-in ones and analyzers in the registry are never pruned. An orphan still referenced by a View is not dropped unless --force is given (the drop would leave the View dangling) — without it, it is only signalled. The drop set is confirmed interactively; --yes skips the prompt and a non-interactive run without --yes refuses, by safety.

⚠ On a shared database an orphan may belong to another application — see db/analyzers.md.

Parameters
$input : InputInterface
$output : OutputInterface
$io : SymfonyStyle
Return values
int

analyzersRenderOrphans()

Prints the orphan custom analyzers — on the server but declared by none.

private analyzersRenderOrphans(InputInterface $input, SymfonyStyle $io, array<int, string> $declared) : void

Report only : orphans are never dropped here.

Parameters
$input : InputInterface
$io : SymfonyStyle
$declared : array<int, string>

The analyzer names declared in the registry.

analyzersRenderReport()

Prints one analyzer's {@see DiffReport} as a status line plus one indented line per change.

private analyzersRenderReport(SymfonyStyle $io, DiffReport $report, bool $apply, bool $force) : void
Parameters
$io : SymfonyStyle
$report : DiffReport
$apply : bool

Whether the report comes from analyzerSync().

$force : bool

Whether the sync was forced.

analyzersRepairBody()

Builds the `up()` body of a repair migration for one drifted analyzer: the declared `type` + `properties` are dumped as a flat PHP literal (via {@see toPhpString()}) into a {@see RawAnalyzer}, wrapped in an {@see AnalyzerDefinition} and forced through `analyzerSync()` (path B — same-name drop + recreate + dependent-View rebuild).

private analyzersRepairBody(AnalyzerDefinition $definition) : string
Parameters
$definition : AnalyzerDefinition

The declared analyzer to repair to.

Return values
string

The PHP code of the migration up() body.

analyzersReport()

Walks the declared analyzers and reports (or provisions, in apply mode) their state, with the orphan custom analyzers as a footnote.

private analyzersReport(InputInterface $input, SymfonyStyle $io, bool $apply, bool $force) : int
Parameters
$input : InputInterface
$io : SymfonyStyle
$apply : bool

False → --diff (read-only) ; true → --sync.

$force : bool

Repair drifted analyzers in place (cascade) — only with $apply.

Return values
int

analyzersShortName()

Strips the `dbname::` namespace prefix from an analyzer name.

private analyzersShortName(string $name) : string
Parameters
$name : string
Return values
string

archiveCollections()

The collection names declared by the `*.structure.json` files of an untarred dump — the universe used by an exclude-only profile on restore.

private archiveCollections(string $directory) : array<int, string>
Parameters
$directory : string

The untarred dump directory.

Return values
array<int, string>

buildRunner()

Builds the migration runner from the resolved façade and the command configuration, or null (with an error printed) when no database or no migrations path is available.

private buildRunner(InputInterface $input, SymfonyStyle $io) : MigrationRunner|null
Parameters
$input : InputInterface
$io : SymfonyStyle
Return values
MigrationRunner|null

doctorAccount()

Accounts one diff report into the running doctor state: renders it, bumps the status counter, flips the health flag when the report is not in sync (and was not freshly applied), and collects it when applied. Shared by the model walk and the collection-index registry walk.

private doctorAccount(SymfonyStyle $io, DiffReport $report, bool $apply, array<string, int> &$counters, array<int, DiffReport&$applied, bool &$healthy) : void
Parameters
$io : SymfonyStyle
$report : DiffReport
$apply : bool
$counters : array<string, int>

The status counters, by reference.

$applied : array<int, DiffReport>

The applied reports, by reference.

$healthy : bool

The health flag, by reference.

doctorJournal()

Journals each applied object as a `CreateAction` in the tracking collection — the audit trail of `doctor --apply`, told apart from the versioned migrations by its `additionalType` ({@see MigrationKind::DOCTOR}).

private doctorJournal(InputInterface $input, array<int, DiffReport$applied) : void

Best-effort: nothing is journaled when nothing was applied or the database is unreachable, and a journal failure never fails the run. The migration runner ignores these rows.

Parameters
$input : InputInterface
$applied : array<int, DiffReport>

The reports actually created / repaired.

Tags
throws
ReflectionException

doctorOrphans()

Computes and prints the orphans — collections (non-system) and views on the server that no configured model declares. Report only.

private doctorOrphans(InputInterface $input, SymfonyStyle $io, array<int, string> $declaredCollections, array<int, string> $declaredViews) : array<int, string>

The migrations tracking collection (ArangoMigrationsTrait::$migrationsCollection) is never an orphan: no model declares it, yet both migrate and doctor --apply write their journal there. It is excluded by its configured name (so a renamed tracking collection is honoured), which also keeps it out of the --prune selection.

Parameters
$input : InputInterface
$io : SymfonyStyle
$declaredCollections : array<int, string>

The collections declared by the configured models.

$declaredViews : array<int, string>

The view names declared by the configured models.

Return values
array<int, string>

The orphan labels (collection : name / view : name).

doctorPrune()

Offers the interactive multi-selection of the orphans to remove and drops the chosen ones. Nothing happens in non-interactive mode.

private doctorPrune(InputInterface $input, OutputInterface $output, SymfonyStyle $io, array<int, string> $orphans) : void
Parameters
$input : InputInterface
$output : OutputInterface
$io : SymfonyStyle
$orphans : array<int, string>

The orphan labels (doctorOrphans()).

Tags
throws
ExitException

When the selection is exited.

doctorRenderReport()

Prints one {@see DiffReport} as a status line (labelled with its {@see DiffKind}) plus one indented line per change.

private doctorRenderReport(SymfonyStyle $io, DiffReport $report, bool $apply) : void
Parameters
$io : SymfonyStyle
$report : DiffReport

The report to render.

$apply : bool

Whether the report comes from repair().

dumpAvailableCollections()

Returns the user (non-system) collection names of the live database, or throws when the HTTP API is unavailable — used by the exclusion paths (`--ignore-collection` and exclude-only profiles) that need the universe.

private dumpAvailableCollections(string $endpoint, string $username, string $password, string $database) : array<int, string>
Parameters
$endpoint : string
$username : string
$password : string
$database : string
Return values
array<int, string>

dumpCompleteCollections()

Returns the collection list of a `--complete` backup: every user collection plus the {@see COMPLETE_SYSTEM_COLLECTIONS} that exist on the server. Throws when the HTTP API is unavailable.

private dumpCompleteCollections(string $endpoint, string $username, string $password, string $database) : array<int, string>
Parameters
$endpoint : string
$username : string
$password : string
$database : string
Return values
array<int, string>

isLocalEndpoint()

True when an ArangoDB endpoint targets the local machine.

private isLocalEndpoint(string|null $endpoint) : bool

The host is extracted from the endpoint (e.g. tcp://127.0.0.1:8529, ssl://localhost:8529, http+tcp://[::1]:8529) and matched against the loopback names. Anything else — a remote host or an unparsable value — is treated as non-local, so the restore warns rather than staying silent.

Parameters
$endpoint : string|null
Return values
bool

migrateApply()

Applies the pending migrations, after confirmation.

private migrateApply(InputInterface $input, OutputInterface $output, SymfonyStyle $io, MigrationRunner $runner, array<string, mixed> $pending) : int
Parameters
$input : InputInterface
$output : OutputInterface
$io : SymfonyStyle
$runner : MigrationRunner
$pending : array<string, mixed>
Tags
throws
ArangoException
Return values
int

migrateCreate()

Generates an empty migration shell.

private migrateCreate(SymfonyStyle $io, string $description) : int
Parameters
$io : SymfonyStyle
$description : string
Return values
int

migrateDryRun()

Lists the pending migrations without running them.

private migrateDryRun(SymfonyStyle $io, array<string, mixed> $pending) : int
Parameters
$io : SymfonyStyle
$pending : array<string, mixed>
Return values
int

restoreSelectionLabel()

A human-readable description of the restore selection, for `--dry-run` (the exact exclude-only list is only known once the archive is untarred).

private restoreSelectionLabel(array<string|int, mixed>|null $profile, array<string|int, mixed> $collection) : string
Parameters
$profile : array<string|int, mixed>|null
$collection : array<string|int, mixed>

The CLI --collection selection.

Return values
string

viewsDatabase()

Builds the live {@see Database} client from the command options/configuration, or null (with an error printed) when no usable endpoint is available.

private viewsDatabase(InputInterface $input, SymfonyStyle $io) : Database|null
Parameters
$input : InputInterface
$io : SymfonyStyle
Return values
Database|null

viewsDrop()

Drops the given views (comma-separated), or offers an interactive selection across the views of the database.

private viewsDrop(InputInterface $input, OutputInterface $output, SymfonyStyle $io, string|null $names) : int
Parameters
$input : InputInterface
$output : OutputInterface
$io : SymfonyStyle
$names : string|null

Comma-separated view names, or null to select interactively.

Tags
throws
ExitException

When the interactive selection is exited.

Return values
int

viewsList()

Lists the views of the database (name, type, linked collections).

private viewsList(InputInterface $input, SymfonyStyle $io) : int
Parameters
$input : InputInterface
$io : SymfonyStyle
Return values
int

viewsRenderOrphans()

Prints the orphan views — on the server but declared by none of the configured models. Report only : orphans are never dropped here, use `--drop` explicitly.

private viewsRenderOrphans(InputInterface $input, SymfonyStyle $io, array<int, string> $declared) : void
Parameters
$input : InputInterface
$io : SymfonyStyle
$declared : array<int, string>

The view names declared by the configured models.

viewsRenderReport()

Prints one model's {@see DiffReport} as a status line plus one indented line per change.

private viewsRenderReport(SymfonyStyle $io, string $id, DiffReport $report, bool $apply) : void
Parameters
$io : SymfonyStyle
$id : string

The container id of the model.

$report : DiffReport

The report to render.

$apply : bool

Whether the report comes from viewSync().

viewsReport()

Walks the configured models and reports (or repairs, in apply mode) the state of their declared views, with the orphan views of the database as a footnote.

private viewsReport(InputInterface $input, SymfonyStyle $io, bool $apply, string|null $only) : int
Parameters
$input : InputInterface
$io : SymfonyStyle
$apply : bool

False → --diff (read-only) ; true → --sync.

$only : string|null

Comma-separated view names to restrict the sync to.

Return values
int

viewsReportSearchAliases()

Reconciles the database-level `search-alias` view registry (the `searchAliasViews` init key) — the federated counterpart of the model-driven loop. Declared names are appended to `$declared` so they are not later flagged as orphans.

private viewsReportSearchAliases(InputInterface $input, SymfonyStyle $io, bool $apply, array<int, string>|null $filter, array<int, string> &$declared) : int
Parameters
$input : InputInterface
$io : SymfonyStyle
$apply : bool

False → diff (read-only) ; true → sync.

$filter : array<int, string>|null

Restrict to these view names, or null for all.

$declared : array<int, string>

The declared view names, appended by reference.

Return values
int

ExitCode::FAILURE when a view is unreachable, ExitCode::SUCCESS otherwise.

On this page

Search results