Skip to content

Instantly share code, notes, and snippets.

@lars-erik
Created October 10, 2023 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lars-erik/e95f7e072570a805357fb6b0a552b69d to your computer and use it in GitHub Desktop.
Save lars-erik/e95f7e072570a805357fb6b0a552b69d to your computer and use it in GitHub Desktop.
Umbraco Document Types to PlantUML
param (
$Server,
$Database,
$Direction = "left to right",
$IncludeDoctypes = $true,
[Switch]
$IncludeElements = $false,
[Switch]
$IncludeProperties = $false
)
$DocTypesSql = @"
SELECT
n.uniqueid,
ct.alias,
n.text,
isContainer,
isElement,
allowAtRoot,
icon
from
cmsContentType ct
inner join umbracoNode n on
n.id = ct.nodeId
where
n.nodeObjectType = 'A2CB7800-F571-4787-9638-BC48539A0EFB'
"@
$PropertiesSql = @"
SELECT
n.uniqueId,
ct.alias,
pt.Alias [propertyAlias],
pt.Name [propertyName],
dt.propertyEditorAlias,
dtn.text
from
cmsContentType ct
inner join umbracoNode n on
n.id = ct.nodeId
inner join cmsPropertyType pt on
pt.contentTypeId = n.id
inner join umbracoDataType dt on
dt.nodeId = pt.dataTypeId
inner join umbracoNode dtn on
dtn.id = dt.nodeId
where
n.nodeObjectType = 'A2CB7800-F571-4787-9638-BC48539A0EFB'
"@
$CompositionsSql = @"
SELECT
parent.uniqueId parentId,
parentCt.alias parentAlias,
parent.text parentText,
child.uniqueId childId,
childCt.alias childAlias,
child.text childText
FROM
cmsContentType2ContentType
inner join umbracoNode parent on
parent.id = parentContentTypeId
inner join cmsContentType parentCt on
parentCt.nodeId = parent.id
inner join umbracoNode child on
child.id = childContentTypeId
inner join cmsContentType childCt on
childCt.nodeId = child.id
"@
$AllowedTypesSql = @"
SELECT
parent.uniqueId parentId,
parentCt.alias parentAlias,
parent.text parentText,
child.uniqueId childId,
childCt.alias childAlias,
child.text childText
FROM
[cmsContentTypeAllowedContentType] cta
inner join umbracoNode parent on
parent.id = cta.Id
inner join cmsContentType parentCt on
parentCt.nodeId = parent.id
inner join umbracoNode child on
child.id = cta.AllowedId
inner join cmsContentType childCt on
childCt.nodeId = child.id
"@
$DocTypes = Invoke-Sqlcmd -ServerInstance $Server -Database $Database -Query $DocTypesSql
$Properties = Invoke-Sqlcmd -ServerInstance $Server -Database $Database -Query $PropertiesSql
$Compositions = Invoke-Sqlcmd -ServerInstance $Server -Database $Database -Query $CompositionsSql
$AllowedTypes = Invoke-Sqlcmd -ServerInstance $Server -Database $Database -Query $AllowedTypesSql
"@startuml
hide empty members
$($Direction) direction
"
$FilteredTypes = $DocTypes | where {
($_.isElement -and $IncludeElements) `
-or `
($_.isElement -eq $false -and $IncludeDoctypes)
}
$FilteredAliases = $FilteredTypes | % { $_.alias }
$FilteredTypes | % {
$dtAlias = $_.alias
"class $($_.alias) as ""$($_.text)"" {"
if ($IncludeProperties) {
$Properties | where { $_.alias -eq $dtAlias } | % {
" + $($_.propertyName) : $($_.propertyEditorAlias)"
}
}
"}"
}
$Compositions | where { $FilteredAliases -contains $_.parentAlias } | % {
"$($_.childAlias) -up-|> $($_.parentAlias)"
}
$AllowedTypes | where { $FilteredAliases -contains $_.parentAlias } | % {
"$($_.parentAlias) *-- $($_.childAlias)"
}
"@enduml"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment