Oihana PHP Arango

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

Manages the **custom** ArangoSearch analyzers of the database, from the declarative registry ({@see ArangoAnalyzersTrait}) — the analyzer counterpart of {@see ArangoViewsAction}.

The default behaviour lists the custom analyzers of the live database (built-in ones are summarized as a count). The other modes:

  • --diff : compares each declared AnalyzerDefinition with the server (DiffStatus) and lists the orphan custom analyzers (on the server, declared by none).
  • --sync : same walk, but missing analyzers are created; drifted ones are only signalled (immutable). With --force, drifted analyzers are repaired in place — drop + recreate + rebuild of their dependent Views.
  • --fix : generates one ready-to-review repair migration per drifted analyzer (the same-name drop + recreate, deferred and versioned) — it writes files and never touches the database. Review them, then run migrate.
  • --prune : drops the orphan custom analyzers (on the server, declared by none), after confirmation. An orphan still used by a View is only dropped with --force (it leaves the View dangling). Built-in analyzers are never pruned.

Analyzers are declared once at the database level via the analyzers init key (ArangoCommandParam::ANALYZERS), not per model — they are shared and database-scoped.

Tags
author

Marc Alcaraz (ekameleon)

since
1.3.0

Table of Contents

Properties

$analyzers  : array<int, AnalyzerDefinition>|AnalyzerDefinition
The declared custom analyzers — a list of {@see AnalyzerDefinition} (a single one is tolerated in place of a one-element list).
$migrationsCollection  : string
The tracking collection name (one per database).
$migrationsNamespace  : string
The PHP namespace the version classes are declared in (e.g. `fr\bouney\migrations`).
$migrationsPath  : string|null
The directory holding the `Version*.php` migration files.

Methods

getAnalyzerDefinitions()  : array<int, AnalyzerDefinition>
Returns the declared analyzers normalized to a flat {@see AnalyzerDefinition} list: a lone `AnalyzerDefinition` becomes a one-element list, and any entry that is not an `AnalyzerDefinition` is dropped (defensive against a malformed declaration).
agent()  : string
The acting agent (`user@host`) stamped on the tracking documents — shared by the `migrate` runs and the `doctor --apply` journal.
analyzers()  : int
Manages the custom analyzers of the database.
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.
gitCommit()  : string|null
The current git commit hash, or null outside a git repository — the history link stamped on every tracking document.
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.
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.

Properties

$migrationsCollection

The tracking collection name (one per database).

public string $migrationsCollection = 'migrations'

$migrationsNamespace

The PHP namespace the version classes are declared in (e.g. `fr\bouney\migrations`).

public string $migrationsNamespace = ''

$migrationsPath

The directory holding the `Version*.php` migration files.

public string|null $migrationsPath = null

Methods

getAnalyzerDefinitions()

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

public getAnalyzerDefinitions() : array<int, AnalyzerDefinition>
Return values
array<int, AnalyzerDefinition>

agent()

The acting agent (`user@host`) stamped on the tracking documents — shared by the `migrate` runs and the `doctor --apply` journal.

protected agent() : string
Return values
string

analyzers()

Manages the custom analyzers of the database.

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

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

gitCommit()

The current git commit hash, or null outside a git repository — the history link stamped on every tracking document.

protected gitCommit() : string|null
Return values
string|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

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
On this page

Search results