Oihana PHP Arango

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

Manages the ArangoSearch views of the ArangoDB database.

The default behaviour lists the views of the live database through ArangoClientTrait::buildDatabase() (like the collections action). Three additional modes are available:

  • --diff : compares the AQL::VIEW declaration of every configured model with the server state and reports the differences (DiffStatus), plus the orphan views (on the server, declared by no model). Read-only — the lazy provisioning of the inspected models is disabled through the container lazy entry.
  • --sync[=a,b] : same walk, but missing views are created and drifted ones repaired with updateProperties().
  • --drop[=a,b] : drops the given views (comma-separated), or offers an interactive selection when no name is provided.

The models to inspect are supplied via the models init key (ArangoCommandParam::MODELS) as a list of container ids of Documents definitions — the same decoupling as the dump/restore configuration.

Tags
author

Marc Alcaraz (ekameleon)

since
1.2.0

Table of Contents

Properties

$models  : array<int, string>
Container ids of the `Documents` models to inspect.
$searchAliasViews  : array<int, SearchAliasView>|SearchAliasView
The declared search-alias views — a list of {@see SearchAliasView} (a single one is tolerated in place of a one-element list).

Methods

getSearchAliasViews()  : array<int, SearchAliasView>
Returns the declared search-alias views normalized to a flat {@see SearchAliasView} list: a lone `SearchAliasView` becomes a one-element list, and any entry that is not a `SearchAliasView` is dropped (defensive against a malformed declaration).
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.
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.
views()  : int
Manages the views of the database.
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.

Properties

$models

Container ids of the `Documents` models to inspect.

public array<int, string> $models = []

Methods

getSearchAliasViews()

Returns the declared search-alias views normalized to a flat {@see SearchAliasView} list: a lone `SearchAliasView` becomes a one-element list, and any entry that is not a `SearchAliasView` is dropped (defensive against a malformed declaration).

public getSearchAliasViews() : array<int, SearchAliasView>
Return values
array<int, SearchAliasView>

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

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

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

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