class RecordManager implements RecordManagerInterface (View source)

Creates, updates and deletes records for the web UI, with validation, logging and serial updates.

Constants

private MAX_BACKEND_REASON_LENGTH

private NAME_CONTENT_TYPES

Types whose whole content is one or more domain names

private NAME_TARGET_TYPES

Types whose content ends in a domain name after numeric fields, such as the SRV weight and port

Methods

__construct(TransactionInterface $transaction, ConfigurationInterface $config, DnsRecordValidationServiceInterface $validationService, SOARecordManagerInterface $soaRecordManager, DomainRepositoryInterface $domainRepository, RepositoryFactoryInterface $repositoryFactory, Closure $dnssecProvider, RecordWriteBackendInterface&BackendCapabilitiesInterface $backendProvider, PermissionService $permissionService, RecordChangeWriterInterface $changeLogger, TemplateRecordLinkRepositoryInterface $templateLinks, ActorInterface $actor, LoggerInterface|null $logger = null, ZoneCacheFlusherInterface|null $zoneCacheFlusher = null)

Constructor

static bool
sameContent(string $type, string $content, string $stored)

Content equality as the duplicate checks see it: exact, domain names compared without case as DNS does, the unquoted ech form, or the same AAAA address written another way.

bool
addRecord(int $zone_id, string $name, string $type, string $content, int $ttl, mixed $prio)

Add a record

addRecordGetId(int $zone_id, string $name, string $type, string $content, int $ttl, mixed $prio, int $disabled = 0, bool $finalizeZone = true, array|null $comment = null, bool $dryRun = false, array $vacated = [])

Add a record and return its ID

static string|null
cleanBackendReason(string $reason)

One line, control characters removed, capped; null when nothing is left.

static string
backendFailureMessage(string $message, string|null $reason)

The failure text with the backend's own reason appended: "Failed to add record to DNS backend: ". The reason is untranslated text from PowerDNS, stripped of control characters and capped; the caller escapes it on output like any message.

static bool
recordFieldsDiffer(array $before, array $after)

Whether two stored copies of a record differ in any field that PowerDNS serves.

editRecord(array $record, bool $finalizeZone = true, array|null $comment = null, bool $dryRun = false, array $vacated = [])

Edit a record

previewEdit(array $record)

Runs an edit's permission checks and validation, but not the duplicate check, and writes nothing. A save that moves several records first previews each one: only a record that passes and really moves goes into the vacated set of the real writes.

deleteRecord(int|string $rid, bool $finalizeZone = true, bool $dryRun = false)

Delete a record by a given record id

void
finalizeZone(int $zoneId, bool $bumpSerial = true, bool $rrsetWritten = true)

What every single write ends with: bump the serial (unless told not to) and rectify. Batch callers pass finalizeZone=false to the writes and call this once when they are done; one holding a transaction bumps the serial inside it and calls this with bumpSerial=false after the commit, since PowerDNS rectifies from committed rows. $rrsetWritten is false when nothing was sent to the backend (no-op save, zone comment), so the API backend bumps the serial itself.

editZoneComment(int $zone_id, string $comment)

Edit the zone comment

Details

__construct(TransactionInterface $transaction, ConfigurationInterface $config, DnsRecordValidationServiceInterface $validationService, SOARecordManagerInterface $soaRecordManager, DomainRepositoryInterface $domainRepository, RepositoryFactoryInterface $repositoryFactory, Closure $dnssecProvider, RecordWriteBackendInterface&BackendCapabilitiesInterface $backendProvider, PermissionService $permissionService, RecordChangeWriterInterface $changeLogger, TemplateRecordLinkRepositoryInterface $templateLinks, ActorInterface $actor, LoggerInterface|null $logger = null, ZoneCacheFlusherInterface|null $zoneCacheFlusher = null)

Constructor

Parameters

TransactionInterface $transaction

Wraps a record write and its serial bump

ConfigurationInterface $config

Configuration manager

DnsRecordValidationServiceInterface $validationService

DNS record validation service

SOARecordManagerInterface $soaRecordManager

SOA record manager

DomainRepositoryInterface $domainRepository

Domain repository

RepositoryFactoryInterface $repositoryFactory

Builds the record and comment repositories

Closure $dnssecProvider

Built on first use, so DNSSEC-disabled installs never construct one

RecordWriteBackendInterface&BackendCapabilitiesInterface $backendProvider

Writes records and says whether a local transaction wraps them

PermissionService $permissionService

Edit levels and zone ownership of the acting user

RecordChangeWriterInterface $changeLogger

Receives the before/after record snapshots

TemplateRecordLinkRepositoryInterface $templateLinks

Drops the template link of a deleted record

ActorInterface $actor

The user the edit gates are about

LoggerInterface|null $logger
ZoneCacheFlusherInterface|null $zoneCacheFlusher

Tells PowerDNS about committed writes, null when it needs no telling

static bool sameContent(string $type, string $content, string $stored)

Content equality as the duplicate checks see it: exact, domain names compared without case as DNS does, the unquoted ech form, or the same AAAA address written another way.

Parameters

string $type
string $content
string $stored

Return Value

bool

bool addRecord(int $zone_id, string $name, string $type, string $content, int $ttl, mixed $prio)

Add a record

This function validates it if correct it inserts it into the database.

Parameters

int $zone_id

Zone ID

string $name

Name part of record

string $type

Type of record

string $content

Content of record

int $ttl

Time-To-Live of record

mixed $prio

Priority of record

Return Value

bool

true if successful; addRecordGetId() carries the reason for a refusal

RecordWriteResult addRecordGetId(int $zone_id, string $name, string $type, string $content, int $ttl, mixed $prio, int $disabled = 0, bool $finalizeZone = true, array|null $comment = null, bool $dryRun = false, array $vacated = [])

Add a record and return its ID

This function validates and inserts a record into the database, returning the new record's ID for use with per-record comments.

Parameters

int $zone_id

Zone ID

string $name

Name part of record

string $type

Type of record

string $content

Content of record

int $ttl

Time-To-Live of record

mixed $prio

Priority of record

int $disabled

Whether the record is created in disabled state (0 or 1)

bool $finalizeZone

Bump the serial and rectify; a batch caller does that once itself

array|null $comment

RRset comment ['content' => string, 'account' => string]; the API backend writes it in the same PATCH as the record, SQL ignores it

bool $dryRun

Run every check and stop before anything is written

array $vacated

Stored content by id of records the same write removes first (an RRset replace); they no longer conflict

Return Value

RecordWriteResult

The new record id, or the reason the write was refused

static string|null cleanBackendReason(string $reason)

One line, control characters removed, capped; null when nothing is left.

Parameters

string $reason

Return Value

string|null

static string backendFailureMessage(string $message, string|null $reason)

The failure text with the backend's own reason appended: "Failed to add record to DNS backend: ". The reason is untranslated text from PowerDNS, stripped of control characters and capped; the caller escapes it on output like any message.

Parameters

string $message
string|null $reason

Return Value

string

static bool recordFieldsDiffer(array $before, array $after)

Whether two stored copies of a record differ in any field that PowerDNS serves.

Parameters

array $before

Record row as stored before the edit

array $after

Record row as stored after the edit

Return Value

bool

RecordWriteResult editRecord(array $record, bool $finalizeZone = true, array|null $comment = null, bool $dryRun = false, array $vacated = [])

Edit a record

This function validates it if correct it inserts it into the database.

Parameters

array $record

Record structure to update

bool $finalizeZone

Bump the serial and rectify; a batch caller does that once itself

array|null $comment

RRset comment ['content' => string, 'account' => string] to store with the record where the backend keeps them together

bool $dryRun

Run every check and stop before anything is written

array $vacated

Stored content by record id of the records the same save moves to another name, type or content, as previewEdit() reports it. A sibling still holding that content is not counted as a copy, so a swap or rotation passes; the API backend ignores it. The caller must run the writes in one transaction and roll back on any refusal.

Return Value

RecordWriteResult

RecordWriteResult previewEdit(array $record)

Runs an edit's permission checks and validation, but not the duplicate check, and writes nothing. A save that moves several records first previews each one: only a record that passes and really moves goes into the vacated set of the real writes.

Parameters

array $record

Record structure to update

Return Value

RecordWriteResult

On success, vacates holds the stored name, type and content the record leaves (null when it stays) and key its validated ones

RecordWriteResult deleteRecord(int|string $rid, bool $finalizeZone = true, bool $dryRun = false)

Delete a record by a given record id

Parameters

int|string $rid

Record ID

bool $finalizeZone

Bump the serial and rectify; a batch caller does that once itself

bool $dryRun

Run every check and stop before anything is written

Return Value

RecordWriteResult

void finalizeZone(int $zoneId, bool $bumpSerial = true, bool $rrsetWritten = true)

What every single write ends with: bump the serial (unless told not to) and rectify. Batch callers pass finalizeZone=false to the writes and call this once when they are done; one holding a transaction bumps the serial inside it and calls this with bumpSerial=false after the commit, since PowerDNS rectifies from committed rows. $rrsetWritten is false when nothing was sent to the backend (no-op save, zone comment), so the API backend bumps the serial itself.

Parameters

int $zoneId
bool $bumpSerial
bool $rrsetWritten

Return Value

void

RecordWriteResult editZoneComment(int $zone_id, string $comment)

Edit the zone comment

This function validates it if correct it inserts it into the database.

Parameters

int $zone_id

Zone ID

string $comment

Comment to set

Return Value

RecordWriteResult

Success, or the reason the write was refused