Last active
April 9, 2024 15:11
-
-
Save AdamNaj/aa4a420b0c9608588782f42e7dab5c2f to your computer and use it in GitHub Desktop.
Assert Tenant Templates from source tenant are also in the second tenant and contain the same base templates.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$aName = "Metro" | |
$aName = "Crafted" | |
$fromName = "/$aName/" | |
$toName = "/$($aName)VC/" | |
$tenantFrom = gci "master:\templates\Project$fromName" | ? { $_.TemplateName -eq "Template" } | |
$tenantFromIDs = $tenantFrom.ID; | |
$tenantTo = gci "master:\templates\Project$toName" | ? { $_.TemplateName -eq "Template" } | |
$tenantToIDs = $tenantTo.ID; | |
$templateGroups = (($tenantFrom + $tenantTo) | Group-Object -Property "Name") | |
$templateGroups | % { | |
$fromTemplate = $_.Group | ? { $_.Paths.Path.Contains($fromName) } | |
$toTemplate = $_.Group | ? { $_.Paths.Path.Contains($toName) } | |
if($toTemplate -eq $null) | |
{ | |
Write-Host "'$($fromTemplate.Name)' template is missing in $toName" -f Red | |
} elseif($fromTemplate -eq $null){ | |
Write-Host "'$($toTemplate.Name)' template is missing in $fromName" -f Yellow | |
} else { | |
$fromTemplateBase = $fromTemplate._.'__Base template'.GetItems(); | |
$fromTemplateBaseIDs = @() + $fromTemplateBase.ID; | |
$toTemplateBase = $toTemplate._.'__Base template'.GetItems(); | |
$toTemplateBaseIDs = @() + $toTemplateBase.ID; | |
$fromTemplateBaseIDs | ? { !$toTemplateBaseIDs.Contains($_) -and !$tenantFromIDs.Contains($_)} | | |
%{ | |
$missingTemplate = gi master: -ID $_ | |
if($missingTemplate.Paths.Path.Contains("/Project/")){ | |
Write-Host "$($fromTemplate.Paths.Path) inherit from $($missingTemplate.Paths.Path) - most likely wrongly" -f Red | |
} elseif ($missingTemplate.Paths.Path.Contains("/sitecore/templates/System/")){ | |
Write-Host "$($fromTemplate.Paths.Path) inherit from $($missingTemplate.Paths.Path) - unnecessarily?" -f Red | |
} else { | |
Write-Host "$($toTemplate.Paths.Path) Should inherit from $($missingTemplate.Paths.Path) - implementing the change" -f Green | |
Add-BaseTemplate -Item $toTemplate -TemplateItem $missingTemplate -WhatIf | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment