Sitecore PowerShell

Bloggat, Sitecore, Utveckling

Migrate renderings from SC7 to SC8

To be able for each language versions of an item to have their own renderings in our Sitecore instance version 7.2, the __Renderings field shared option was set to false. This is not Sitecore Best Practice, but this is how it was solved. When migrating the content to Sitecore 8.2 I wrote a Power Shell script to migrate the rendering settings to the new __Final Rendering field.

Sitecore PowerShell

PowerShell for Sitecore

Our setup uses Language Fallback and all languages are configured to fallback on the EN language. Even the __Renderings field is Language Fallback enabled.

First I took a copy of the SC72 environment to a new instance to avoid working with the live content. Then I installed the excellent PowerShell for Sitecore plugin and pasted the following code in the ISE interface.

These are the steps in details:

  1. Export and import the __Final Renderings field item {04BF00DB-F5FB-41F7-8AB7-22408372A981} from SC8.2 to Stage 7.2
    Change it to an ordinary single line text because SC72 cannot handle more than 1 layout field
  2. Copy all media using serialization and copy paste the files from prod to new instance.
    First clear the serialization folder on the server
  3. Copy all the content from the prod environemnt to the 7.2 stage environment
    Use Sitecore Package. Sitecore/Content/SITE add with Subitems. Use Replace
  4. SC72: Copy Renderings to the new Final Renderings field using the following script
$rootPath = "master:\content\SITE\Home"
$emptyRendering = @"
<r xmlns:p="p" xmlns:s="s" p:p="1" />
"@

# First copy EN renderings to the Final Renderings field to gain Language Fallback on the other languages
$items = (Get-Item -Path $rootPath -Version * -Language en) + (Get-ChildItem -Path $rootPath -recurse -Version * -Language en)

ForEach ($item in $items) {
    $Renderings = $item."__Renderings"
    if($Renderings -ne $null) {
        $item."__Final Renderings" = $Renderings
        Write-Host "Setting Final Renderings for item '$($item.ID)' language '$($item.Language)'"
    }
}

# Then copy language renderings to the Final Renderings field on the language versions in case it differ from the EN version
$items = Get-ChildItem -WithParent -Path $rootPath -recurse -Version * -Language da-DK, de-AT, de-CH, de-DE, en-AU, en-GB, en-US, es-ES, fi-FI, fr-BE, fr-CH, fr-FR, it-IT, ko-KR, nb-NO, nl-BE, nl-NL, pt-BR, sv-SE, zh-CN

ForEach ($item in $items) {
   Reset-ItemField -Item $Item -Name "__Final Renderings" -IncludeStandardFields # No need if first time to run
    $ENItem = Get-Item master: -ID $item.ID -Language en
    if($ENItem -ne $null) {
        $ENrenderings = $ENitem."__Renderings"
    }

    $Renderings = $item."__Renderings"
    if($Renderings -ne $null) {
        if($Renderings -ne $ENrenderings) {
            $item."__Final Renderings" = $Renderings
            Write-Host "Setting Final Renderings for item '$($item.ID)' language '$($item.Language)'"
        }

        if($Renderings -eq $emptyRendering) {
            Reset-ItemField -Item $item -Name "__Final Renderings" -IncludeStandardFields
            Write-Host "Reset Final Renderings for item '$($item.ID)' language '$($item.Language)'"
        }
    }
}

The script took about 1 hour to execute because of the large amount of content. The I exported all content by creating a SC package and imported it to the new SC82 instance. The media was serialized and reverted on the SC82 instance. Finally I run this clean up script in the SC82 environment to reset the language specific renderings on the EN item.

$rootPath = "master:\content\SITE\Home"

# Reset the Renderings Field on the EN version
$items = Get-ChildItem -WithParent -Path $rootPath -recurse -Version * -Language en

ForEach ($item in $items) {
    Reset-ItemField -Item $item -Name "__Final Renderings" -IncludeStandardFields
}

By  -      


Lämna ett svar

Din e-postadress kommer inte publiceras. Obligatoriska fält är märkta *