class DbZoneTemplateRepository implements ZoneTemplateRepositoryInterface (View source)

SQL persistence for zone templates in zone_templ and their records in zone_templ_records.

The zone listings join the PowerDNS tables on SQL backends; on the API backend they read the Poweradmin-native zones table only and take zone details from the backend provider.

Constants

private DEFAULT_SOA_NAME

Default SOA record stamped into a template that carries none.

private DEFAULT_SOA_CONTENT

Methods

__construct(object $db, ConfigurationInterface|null $config = null, DnsBackendProviderInterface|null $backendProvider = null)

No description

array
listZoneTemplates(int|null $userId, bool $isUeberuser)

List zone templates visible to the given user

static string
visibleToUserSql(string $alias, string $userParam, string $groupUserParam)

WHERE condition for the templates a user may see: global ones, their own, and those shared with a group they belong to. Takes two placeholders bound to the same user id, since native MySQL prepares cannot reuse one.

bool
isSharedWithUser(int $templateId, int $userId)

Whether the template is shared with a group the user belongs to.

array
listGroupsForTemplates(array $templateIds, int|null $viewerId = null)

Groups each template is shared with, sorted by name. With a viewer, a template the viewer does not own lists only the groups the viewer belongs to.

void
replaceTemplateGroups(int $templateId, array $groupIds)

Replace the groups a template is shared with.

array|false
getZoneTemplateDetails(int $id)

Get zone template details by ID

string
getTemplateNameForZone(int|string $zoneId)

Get the template name linked to a zone

array
getZoneTemplateRecords(int $templateId, int $rowStart = 0, int $rowAmount = Constants::DEFAULT_MAX_ROWS, string $sortBy = 'name')

Get all records for a zone template

array
getZoneTemplateRecordById(int $id, int|null $templateId = null)

Get a single zone template record by ID

int
countZoneTemplateRecords(int $templateId)

Count records in a zone template

int|null
findFlaggedDefaultTemplateId()

ID of the global template flagged is_default, if any

bool
globalTemplateExists(int $id)

Whether a global template (owner 0) with this ID exists

array
findGlobalTemplateIdsByName(string $name)

Find global templates (owner 0) by name

void
flagDefaultTemplate(int $templateId)

Flag one global template as the default, clearing every other global template

void
clearDefaultTemplate()

Clear the system-wide default template flag

int
createZoneTemplate(string $name, string $description, int $owner, int $createdBy, array $groupIds = [])

Create a new zone template with a default SOA record

int
createZoneTemplateWithRecords(string $name, string $description, int $owner, int $createdBy, array $records, array $groupIds = [])

Create a zone template together with its records, in one transaction

bool
updateZoneTemplate(int $id, string $name, string $description, int|null $owner = null)

Update a zone template

bool
deleteZoneTemplate(int $id)

Delete a zone template and all related records

void
deleteZoneTemplatesOwnedBy(int $ownerId)

Deletes every template the user owns, with its records and zone links.

array
listSharedTemplatesOwnedBy(int $ownerId)

The user's templates that are shared with at least one group, sorted by name.

void
handOverSharedTemplates(int $ownerId, int $heirId)

Give the user's shared templates to another user, so the groups keep them when the owner is deleted. Runs inside the caller's transaction.

int
addRecord(int $templateId, string $name, string $type, string $content, int $ttl, int $prio)

Add a record to a zone template

bool
updateRecord(int $id, string $name, string $type, string $content, int $ttl, int $prio)

Update a zone template record

bool
deleteRecord(int $id)

Delete a zone template record

bool
unlinkZoneFromTemplate(int $zoneId)

Unlink a zone from its template

int
getTemplateIdForZone(int $zoneId)

The template a zone is linked to.

void
assignTemplateToZone(int $zoneId, int $templateId)

Point a zone at a template; 0 unlinks it.

array
listZoneRowIds(int $zoneId)

The zones.id rows of a zone. A zone shared by several owners has one row per owner, and the template sync state keys on that id.

bool
zoneTemplateExists(int $id)

Check if a zone template exists

bool
zoneTemplateNameExists(string $name, int|null $excludeId = null)

Check if a zone template name already exists

array
findTemplateIdsByName(string $name)

Find every template ID carrying the given name

bool
isOwner(int $templateId, int $userId)

Check if user is the owner of a zone template

int|null
getOwner(int $templateId)

Get the owner ID of a zone template

array
listLinkedZoneIds(int $templateId, int|null $ownerId)

Zone IDs of the zones linked to a template

array
listLinkedZoneIdPairs(int $templateId, int|null $ownerId)

Both ids of every zone linked to a template

array
listLinkedZones(int $templateId, int|null $ownerId)

The zones linked to a template with name, type, record count and owner details

array
getZonesByIds(array $zoneIds)

Name and type of the given zones

Details

__construct(object $db, ConfigurationInterface|null $config = null, DnsBackendProviderInterface|null $backendProvider = null)

No description

Parameters

object $db
ConfigurationInterface|null $config
DnsBackendProviderInterface|null $backendProvider

array listZoneTemplates(int|null $userId, bool $isUeberuser)

List zone templates visible to the given user

Parameters

int|null $userId

User ID (null together with $isUeberuser = true lists all)

bool $isUeberuser

Whether the user may see every template

Return Value

array

List of zone templates

static string visibleToUserSql(string $alias, string $userParam, string $groupUserParam)

WHERE condition for the templates a user may see: global ones, their own, and those shared with a group they belong to. Takes two placeholders bound to the same user id, since native MySQL prepares cannot reuse one.

Parameters

string $alias
string $userParam
string $groupUserParam

Return Value

string

bool isSharedWithUser(int $templateId, int $userId)

Whether the template is shared with a group the user belongs to.

Parameters

int $templateId
int $userId

Return Value

bool

array listGroupsForTemplates(array $templateIds, int|null $viewerId = null)

Groups each template is shared with, sorted by name. With a viewer, a template the viewer does not own lists only the groups the viewer belongs to.

Parameters

array $templateIds
int|null $viewerId

Return Value

array

Keyed by template ID; unshared templates are absent

void replaceTemplateGroups(int $templateId, array $groupIds)

Replace the groups a template is shared with.

Parameters

int $templateId
array $groupIds

Return Value

void

array|false getZoneTemplateDetails(int $id)

Get zone template details by ID

Parameters

int $id

Zone template ID

Return Value

array|false

Template details or false if not found

string getTemplateNameForZone(int|string $zoneId)

Get the template name linked to a zone

Parameters

int|string $zoneId

Zone ID (zones.id, or the canonical id column on API backends)

Return Value

string

Template name, or an empty string when the zone has no template

array getZoneTemplateRecords(int $templateId, int $rowStart = 0, int $rowAmount = Constants::DEFAULT_MAX_ROWS, string $sortBy = 'name')

Get all records for a zone template

Parameters

int $templateId

Zone template ID

int $rowStart

Starting row

int $rowAmount

Number of rows

string $sortBy

Column to sort by

Return Value

array

Template records

array getZoneTemplateRecordById(int $id, int|null $templateId = null)

Get a single zone template record by ID

Parameters

int $id

Record ID

int|null $templateId

Restrict the lookup to this template, so a record ID from another template cannot be read

Return Value

array

Record details or an empty array

int countZoneTemplateRecords(int $templateId)

Count records in a zone template

Parameters

int $templateId

Zone template ID

Return Value

int

Number of records

int|null findFlaggedDefaultTemplateId()

ID of the global template flagged is_default, if any

Return Value

int|null

Template ID or null when no template is flagged

bool globalTemplateExists(int $id)

Whether a global template (owner 0) with this ID exists

Parameters

int $id

Template ID

Return Value

bool

True if it exists and is global

array findGlobalTemplateIdsByName(string $name)

Find global templates (owner 0) by name

Parameters

string $name

Template name

Return Value

array

Matching template IDs

void flagDefaultTemplate(int $templateId)

Flag one global template as the default, clearing every other global template

Parameters

int $templateId

Template to flag

Return Value

void

void clearDefaultTemplate()

Clear the system-wide default template flag

Return Value

void

int createZoneTemplate(string $name, string $description, int $owner, int $createdBy, array $groupIds = [])

Create a new zone template with a default SOA record

Parameters

string $name

Template name

string $description

Template description

int $owner

Owner user ID (0 for global)

int $createdBy

Creator user ID

array $groupIds

User groups to share it with, written in the same transaction

Return Value

int

New template ID

Exceptions

Exception

int createZoneTemplateWithRecords(string $name, string $description, int $owner, int $createdBy, array $records, array $groupIds = [])

Create a zone template together with its records, in one transaction

Parameters

string $name

Template name

string $description

Template description

int $owner

Owner user ID (0 for global)

int $createdBy

Creator user ID

array $records
array $groupIds

User groups to share it with

Return Value

int

New template ID

Exceptions

Exception

bool updateZoneTemplate(int $id, string $name, string $description, int|null $owner = null)

Update a zone template

Parameters

int $id

Template ID

string $name

New name

string $description

New description

int|null $owner

New owner (null keeps the current one)

Return Value

bool

True on success

bool deleteZoneTemplate(int $id)

Delete a zone template and all related records

Parameters

int $id

Template ID

Return Value

bool

True on success

Exceptions

Exception

void deleteZoneTemplatesOwnedBy(int $ownerId)

Deletes every template the user owns, with its records and zone links.

Runs inside the caller's transaction (used by user deletion).

Parameters

int $ownerId

Owner user ID

Return Value

void

array listSharedTemplatesOwnedBy(int $ownerId)

The user's templates that are shared with at least one group, sorted by name.

Parameters

int $ownerId

Return Value

array

void handOverSharedTemplates(int $ownerId, int $heirId)

Give the user's shared templates to another user, so the groups keep them when the owner is deleted. Runs inside the caller's transaction.

Parameters

int $ownerId
int $heirId

Return Value

void

int addRecord(int $templateId, string $name, string $type, string $content, int $ttl, int $prio)

Add a record to a zone template

Parameters

int $templateId

Template ID

string $name

Record name

string $type

Record type

string $content

Record content

int $ttl TTL
int $prio Priority

Return Value

int

New record ID

bool updateRecord(int $id, string $name, string $type, string $content, int $ttl, int $prio)

Update a zone template record

Parameters

int $id

Record ID

string $name

Record name

string $type

Record type

string $content

Record content

int $ttl TTL
int $prio Priority

Return Value

bool

True on success

bool deleteRecord(int $id)

Delete a zone template record

Parameters

int $id

Record ID

Return Value

bool

True on success

bool unlinkZoneFromTemplate(int $zoneId)

Unlink a zone from its template

Parameters

int $zoneId

Zone ID (zones.domain_id)

Return Value

bool

True on success

int getTemplateIdForZone(int $zoneId)

The template a zone is linked to.

Parameters

int $zoneId

Zone ID (zones.domain_id)

Return Value

int

Template ID, or 0 when the zone has no template or does not exist

void assignTemplateToZone(int $zoneId, int $templateId)

Point a zone at a template; 0 unlinks it.

Parameters

int $zoneId

Zone ID (zones.domain_id)

int $templateId

Zone template ID

Return Value

void

array listZoneRowIds(int $zoneId)

The zones.id rows of a zone. A zone shared by several owners has one row per owner, and the template sync state keys on that id.

Parameters

int $zoneId

Zone ID (zones.domain_id)

Return Value

array

bool zoneTemplateExists(int $id)

Check if a zone template exists

Parameters

int $id

Template ID

Return Value

bool

True if it exists

bool zoneTemplateNameExists(string $name, int|null $excludeId = null)

Check if a zone template name already exists

Parameters

string $name

Template name

int|null $excludeId

Exclude this template ID from the check (for updates)

Return Value

bool

True if the name exists

array findTemplateIdsByName(string $name)

Find every template ID carrying the given name

Parameters

string $name

Zone template name

Return Value

array

Matching template IDs

bool isOwner(int $templateId, int $userId)

Check if user is the owner of a zone template

Parameters

int $templateId

Template ID

int $userId

User ID

Return Value

bool

True if the user is the owner

int|null getOwner(int $templateId)

Get the owner ID of a zone template

Parameters

int $templateId

Template ID

Return Value

int|null

Owner ID (0 for a global template) or null if not found

array listLinkedZoneIds(int $templateId, int|null $ownerId)

Zone IDs of the zones linked to a template

Parameters

int $templateId

Zone template ID

int|null $ownerId

Only zones owned (zones.owner) by this user, or null for all

Return Value

array

Zone IDs (zones.domain_id, or the canonical id on API backends)

array listLinkedZoneIdPairs(int $templateId, int|null $ownerId)

Both ids of every zone linked to a template

Parameters

int $templateId

Zone template ID

int|null $ownerId

Only zones owned (zones.owner) by this user, or null for all

Return Value

array

array listLinkedZones(int $templateId, int|null $ownerId)

The zones linked to a template with name, type, record count and owner details

Parameters

int $templateId

Zone template ID

int|null $ownerId

Only zones owned (zones.owner) by this user, or null for all

Return Value

array

Rows with id, name, type, count_records, owner, comment, owner_name, owner_fullname

array getZonesByIds(array $zoneIds)

Name and type of the given zones

Parameters

array $zoneIds

Zone IDs (non-empty)

Return Value

array

Rows with id, name, type