Skip to content

Instantly share code, notes, and snippets.

@AlexKasaku
Last active October 24, 2016 16:03
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 AlexKasaku/156cce5809a17a422d326d1d65e522b0 to your computer and use it in GitHub Desktop.
Save AlexKasaku/156cce5809a17a422d326d1d65e522b0 to your computer and use it in GitHub Desktop.
# Convert items' Final Layout to an XML Delta version.
$defaultDevice = Get-LayoutDevice "Default"
foreach ( $item in Get-ChildItem -Recurse )
{
# Confirm item has a layout
try {
# Get-Layout can throw an error if layout is badly formed, so we catch it and continue if this happens.
if ((Get-Layout -Item $item -Device $defaultDevice) -eq $null) {
continue;
}
}
catch
{
Write-Host "$($item.FullPath) - Has invalid layout and requires inspection."
continue;
}
# Only interested if a FinalLayout has been set
if ($item.Fields["__Final Renderings"].ContainsStandardValue -or !$item.Fields["__Final Renderings"].Value) {
Write-Host "$($item.FullPath) - No Final Layout set"
continue;
}
$sharedLayout = $item.__Renderings
$finalLayout = $item."__Final Renderings"
if (![Sitecore.Xml.Patch.XmlPatchUtils]::IsXmlPatch($finalLayout))
{
$delta = [Sitecore.Data.Fields.XmlDeltas]::GetDelta($finalLayout, $sharedLayout)
$item."__Final Renderings" = $delta
Write-Host "$($item.FullPath) - Changing to delta"
}
else
{
Write-Host "$($item.FullPath) - Already using patch"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment