Skip to content

Instantly share code, notes, and snippets.

@eliashaeussler
Created August 7, 2023 14:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliashaeussler/025f3216b51d44f5c93a5743bfda1fd6 to your computer and use it in GitHub Desktop.
Save eliashaeussler/025f3216b51d44f5c93a5743bfda1fd6 to your computer and use it in GitHub Desktop.
Query TYPO3 page tree with MySQL 8+
set @rootPageId := 15047;
set @maxDepth := 99;
with recursive children as (
select root.*, 1 as depth
from pages root
where root.uid = @rootPageId
or (root.sys_language_uid > 0 and root.l10n_source = @rootPageId)
and root.deleted = 0
union all
select parent.*, child.depth + 1 as depth
from pages parent
inner join children child
on (child.sys_language_uid = 0 and parent.pid = child.uid)
where parent.deleted = 0
and child.depth < @maxDepth
)
select uid, pid, depth, sys_language_uid, l10n_source
from children
order by depth, sys_language_uid;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment