PageAncestryRepository

readonly class \TYPO3\CMS\Core\Domain\Repository\PageAncestryRepository

Fetches the ancestry of a page - the page itself and all its parent pages up to the virtual tree root - with one recursive common table expression (CTE).

Records are workspace-resolved for the given workspace, but neither language overlays, mount points, relations nor any kind of access restriction besides the deleted flag are applied: this is the raw building block for frontend and backend consumers.

Attributes

#[Autoconfigure]
$public: true

Table of Contents

Constants

MAX_TRAVERSAL_LEVELS  : int = 100

Methods

__construct()  : mixed
findAncestry()  : Generator<int, array<string, mixed>>
Yields the workspace-resolved page records, starting with the page itself and ending with the page on the root level (pid=0), as long as the ancestry is not broken.

Constants

MAX_TRAVERSAL_LEVELS

public int MAX_TRAVERSAL_LEVELS = 100

Methods

findAncestry()

Yields the workspace-resolved page records, starting with the page itself and ending with the page on the root level (pid=0), as long as the ancestry is not broken.

public findAncestry(int $pageId, int $workspaceId[, bool $includeDeleted = false ][, bool $includeWorkspaceDeletedPages = false ]) : Generator<int, array<string, mixed>>

The recursive CTE does the workspace overlay handling within the traversal. Workspace records keep the live uid, with _ORIG_uid pointing to the version record and _ORIG_pid holding the live pid of a moved page. Both are only set if they carry a value.

Deleted pages end the ancestry, unless $includeDeleted is set. Pages deleted in the given workspace end the ancestry as well, unless $includeWorkspaceDeletedPages is set, which yields them with their delete placeholder version.

Rows are yielded one by one, so a consumer stopping early (for example on a mounted page) never sees exceptions caused by records further up.

The created recursive CTE contains two guards against cycling ancestry:

Guard 1 - ancestor path guard:

During the recursing a uid path is created (__CTE_PATH__) and in case that a page is already contained in the parent record __CTE_PATH__ the flag field __CTE_IS_CYCLE__ is set to 1, otherwise it is 0.

If the parent record __CTE_IS_CYLCE__ is 1 no records are retrieved which retrieves a duplicate page record except of this flag. During the record retrieval CircularRootLineException is thrown to abort and state this crucial data corruption.

This guard is designed to abort cycling recursion on the database side as early as possible while still transport the cycling issue information to this method.

Guard 2 - max recursion level guard:

During the recursive CTE handling recursion level info is created (__CTE_LEVEL__) and used as a hard recursion limit fence. That means, if the level reaches self::MAX_TRAVERSAL_LEVELS no more page records are received. In the case that neither GUARD 1, nor PID=0 abort criteria is reached and max level hit a meaningful BrokenRootLineException exception is thrown.

Parameters

$pageId : int
$workspaceId : int
$includeDeleted : bool = false
$includeWorkspaceDeletedPages : bool = false

Tags

throws
BrokenRootLineException
throws
CircularRootLineException
throws
Exception

Return values

Generator<int, array<string, mixed>>
On this page