class DbZoneRepository implements ZoneRepositoryInterface (View source)

SQL zone repository over the PowerDNS domains and records tables plus the zones and zones_groups ownership tables.

Methods

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

No description

array
getDistinctStartingLetters(int $userId, bool $viewOthers)

No description

ZoneSummary>|int
getReverseZones(string $permType, int $userId, string $reverseType = 'all', int $offset = 0, int $limit = 25, string $sortBy = 'name', string $sortDirection = 'ASC', bool $countOnly = false, bool $showSerial = false, bool $showTemplate = false, bool $includeHealth = true, bool $includeRecordCount = true)

Get reverse zones with efficient database-level filtering and pagination

int
countZones(string $permType, int|null $userId, string $letterStart = 'all', string $zoneType = 'forward')

Count the zones a permission scope may see, optionally narrowed by first letter and zone kind.

array
getReverseZoneCounts(string $permType, int $userId)

Get all reverse zone counts in a single query (optimization)

array
listZones(int|null $userId = null, bool $viewOthers = false, array $filters = [], int $offset = 0, int $limit = 100)

Get a complete list of zones accessible by the current user

ZoneDetail|null
getZone(int $zoneId)

Get a zone by ID with full details

array
findForwardZonesByPtrRecords(array $reverseZoneIds)

Find forward zones associated with reverse zones through PTR records

string|null
getZoneComment(int $zoneId)

Get zone comment by zone ID

int|string
createZoneShell(int $domainId, int|null $owner, int $templateId)

Write the native zones row of a zone the backend has just created.

void
deleteZoneShell(int $domainId)

Drop the native zones row of a zone, when the zone is deleted.

void
saveZoneComment(int $zoneId, string $comment)

Set the zone comment, creating the zones row for a zone that has none.

bool
updateZoneComment(int $zoneId, string $comment)

Update zone comment

array
getZoneOwners(int $zoneId)

Get users who own a zone

void
lockZoneOwners(int $zoneId)

Lock the zone's owner rows for the rest of the open transaction, so a concurrent removal waits instead of deciding on stale owner counts.

array
getOwnerIdsByZoneIds(array $zoneIds)

Direct owners of several zones in one query, for list pages.

array
getOwnedZoneIds(int $userId)

Ids of every zone the user owns directly or through a group, in the id space the zone logs and zones_groups use.

bool
addOwnerToZone(int $zoneId, int $userId)

Add owner to zone

bool
removeOwnerFromZone(int $zoneId, int $userId)

Remove owner from zone

bool
isSharedZoneId(int $zoneId)

Whether two zones share this zone id in API backend mode, so owner rows and group grants keyed by it cannot tell the zones apart and are not honoured.

bool|null
handOverNamedZoneRow(int $zoneId, int $fromUserId, int $toUserId)

Give the named zone row a user being deleted holds to another user, so the zone stays.

bool
isUserZoneOwner(int $zoneId, int $userId)

Check if user is already an owner of the zone

bool
deleteZone(int $zoneId)

Delete a zone by ID

bool
updateZone(int $zoneId, array $updates)

Update zone metadata

int
getZoneCount()

Get the total number of zones

int
getZoneCountFiltered(array|null $zoneIds, int|null $userId = null, string|null $nameFilter = null, string|null $nameContains = null)

Get count of zones filtered by zone IDs (permission-aware)

array
getAllZonesFiltered(array|null $zoneIds, int|null $userId = null, string|null $nameFilter = null, int|null $offset = null, int|null $limit = null, string|null $nameContains = null, array $sort = [])

Get all zones filtered by zone IDs (permission-aware)

array|null
getZoneById(int $zoneId)

Get a zone by ID

Details

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

No description

Parameters

$db
$config
DnsBackendProviderInterface|null $backendProvider

array getDistinctStartingLetters(int $userId, bool $viewOthers)

No description

Parameters

int $userId
bool $viewOthers

Return Value

array

ZoneSummary>|int getReverseZones(string $permType, int $userId, string $reverseType = 'all', int $offset = 0, int $limit = 25, string $sortBy = 'name', string $sortDirection = 'ASC', bool $countOnly = false, bool $showSerial = false, bool $showTemplate = false, bool $includeHealth = true, bool $includeRecordCount = true)

Get reverse zones with efficient database-level filtering and pagination

Parameters

string $permType

Permission type ('all', 'own')

int $userId

User ID (used when permType is 'own')

string $reverseType

Filter by reverse zone type ('all', 'ipv4', 'ipv6')

int $offset

Pagination offset

int $limit

Maximum number of records to return

string $sortBy

Column to sort by

string $sortDirection

Sort direction ('ASC' or 'DESC')

bool $countOnly

If true, returns only the count of matching zones

bool $showSerial
bool $showTemplate
bool $includeHealth
bool $includeRecordCount

Return Value

ZoneSummary>|int

Reverse zones keyed by name, or the count if countOnly is true

int countZones(string $permType, int|null $userId, string $letterStart = 'all', string $zoneType = 'forward')

Count the zones a permission scope may see, optionally narrowed by first letter and zone kind.

Parameters

string $permType

Permission type ('all', 'own'); anything else counts nothing

int|null $userId

User ID for 'own'; null counts nothing

string $letterStart

Single first letter, '1' for a leading digit, 'idn' for punycode names, or 'all'

string $zoneType

'forward', 'reverse' or 'all'

Return Value

int

Number of matching zones

array getReverseZoneCounts(string $permType, int $userId)

Get all reverse zone counts in a single query (optimization)

Parameters

string $permType

Permission type ('all', 'own')

int $userId

User ID (used when permType is 'own')

Return Value

array

array listZones(int|null $userId = null, bool $viewOthers = false, array $filters = [], int $offset = 0, int $limit = 100)

Get a complete list of zones accessible by the current user

Parameters

int|null $userId

Optional user ID for filtering

bool $viewOthers

Whether user can view other users' zones

array $filters

Optional filters

int $offset

Pagination offset

int $limit

Maximum number of records

Return Value

array

Zones ordered by name

ZoneDetail|null getZone(int $zoneId)

Get a zone by ID with full details

The getZoneById() core plus comment, secured and the owner list; ZoneDetail::toArray() gives the legacy column-keyed shape.

Parameters

int $zoneId

The zone ID

Return Value

ZoneDetail|null

The zone or null if not found

array findForwardZonesByPtrRecords(array $reverseZoneIds)

Find forward zones associated with reverse zones through PTR records

Optimized 3-step approach instead of slow LIKE JOIN:

  1. Fetch all PTR records for reverse zones
  2. Extract domain suffixes from PTR content in PHP
  3. Look up forward zones with exact IN() match (uses indexes)

Parameters

array $reverseZoneIds

Array of reverse zone IDs

Return Value

array

Array of PTR record matches with forward zone information

string|null getZoneComment(int $zoneId)

Get zone comment by zone ID

Parameters

int $zoneId

The zone ID

Return Value

string|null

The zone comment or null if not found

int|string createZoneShell(int $domainId, int|null $owner, int $templateId)

Write the native zones row of a zone the backend has just created.

Parameters

int $domainId

The zone id the backend returned

int|null $owner

Owning user, null for a zone owned by groups only

int $templateId

Zone template the zone was seeded from, 0 for none

Return Value

int|string

The zones.id the template sync rows key on

void deleteZoneShell(int $domainId)

Drop the native zones row of a zone, when the zone is deleted.

Parameters

int $domainId

Return Value

void

void saveZoneComment(int $zoneId, string $comment)

Set the zone comment, creating the zones row for a zone that has none.

Parameters

int $zoneId
string $comment

Return Value

void

bool updateZoneComment(int $zoneId, string $comment)

Update zone comment

Parameters

int $zoneId

The zone ID

string $comment

The new comment

Return Value

bool

True if updated successfully

array getZoneOwners(int $zoneId)

Get users who own a zone

Parameters

int $zoneId

The zone ID

Return Value

array

Array of user information

void lockZoneOwners(int $zoneId)

Lock the zone's owner rows for the rest of the open transaction, so a concurrent removal waits instead of deciding on stale owner counts.

Parameters

int $zoneId

The zone ID

Return Value

void

array getOwnerIdsByZoneIds(array $zoneIds)

Direct owners of several zones in one query, for list pages.

Parameters

array $zoneIds

Return Value

array

Zone id => owner user ids; zones without a row are absent

array getOwnedZoneIds(int $userId)

Ids of every zone the user owns directly or through a group, in the id space the zone logs and zones_groups use.

Parameters

int $userId

Return Value

array

bool addOwnerToZone(int $zoneId, int $userId)

Add owner to zone

Parameters

int $zoneId

The zone ID

int $userId

The user ID

Return Value

bool

True if added successfully

bool removeOwnerFromZone(int $zoneId, int $userId)

Remove owner from zone

Parameters

int $zoneId

The zone ID

int $userId

The user ID

Return Value

bool

True if removed successfully

bool isSharedZoneId(int $zoneId)

Whether two zones share this zone id in API backend mode, so owner rows and group grants keyed by it cannot tell the zones apart and are not honoured.

Parameters

int $zoneId

Return Value

bool

bool|null handOverNamedZoneRow(int $zoneId, int $fromUserId, int $toUserId)

Give the named zone row a user being deleted holds to another user, so the zone stays.

Null when the backend keeps no such row or the user holds none (add an owner instead); false when the id is shared and the row it opens is not that user's.

Parameters

int $zoneId
int $fromUserId
int $toUserId

Return Value

bool|null

bool isUserZoneOwner(int $zoneId, int $userId)

Check if user is already an owner of the zone

Parameters

int $zoneId

The zone ID

int $userId

The user ID

Return Value

bool

True if user is already an owner

bool deleteZone(int $zoneId)

Delete a zone by ID

Parameters

int $zoneId

The zone ID

Return Value

bool

True if zone was deleted successfully

bool updateZone(int $zoneId, array $updates)

Update zone metadata

Parameters

int $zoneId

The zone ID

array $updates

Array of field => value pairs to update

Return Value

bool

True if zone was updated successfully

int getZoneCount()

Get the total number of zones

Return Value

int

Total number of zones

int getZoneCountFiltered(array|null $zoneIds, int|null $userId = null, string|null $nameFilter = null, string|null $nameContains = null)

Get count of zones filtered by zone IDs (permission-aware)

Parameters

array|null $zoneIds

Optional array of zone IDs to filter

int|null $userId

Optional user ID filter

string|null $nameFilter

Optional name filter

string|null $nameContains

Optional case-insensitive substring filter on the name

Return Value

int

Number of matching zones

array getAllZonesFiltered(array|null $zoneIds, int|null $userId = null, string|null $nameFilter = null, int|null $offset = null, int|null $limit = null, string|null $nameContains = null, array $sort = [])

Get all zones filtered by zone IDs (permission-aware)

Parameters

array|null $zoneIds

Optional array of zone IDs to filter

int|null $userId

Optional user ID filter

string|null $nameFilter

Optional name filter

int|null $offset

Optional pagination offset

int|null $limit

Optional pagination limit

string|null $nameContains

Optional case-insensitive substring filter on the name

array $sort

Sort keys (name, type or id); empty keeps the name order

Return Value

array

Array of matching zones

array|null getZoneById(int $zoneId)

Get a zone by ID

Parameters

int $zoneId

Zone ID

Return Value

array|null

Zone data if found, null otherwise