Last active
October 24, 2016 16:03
-
-
Save AlexKasaku/156cce5809a17a422d326d1d65e522b0 to your computer and use it in GitHub Desktop.
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
# 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