jan-h
4/5/2017 - 7:37 PM

PowerShell script to install hotfix XPM_8.1.1.3571 for SDL Web 8.1.1

PowerShell script to install hotfix XPM_8.1.1.3571 for SDL Web 8.1.1

# This script will apply hotfix XPM_8.1.1.3571 for SDL Web 8.1.1
# Tested on SDL Web 8.1.1. Probably works in a comparable way with hotfix 3571 for SDL Web 8.5 and SDL Tridion 2013 SP1

# To install the hotfix...
# - make sure you have a backup of the SDL Web Content Manager which is located in the %TRIDION_HOME% path.
# - this script will make a backup of the files it touches (it copies .old files), see the filenames in the scripts output verbose messages
# - if you run the script again it will overwrite those backup files.
# - get a copy of the hotfix, unzip it to a folder and set the path to that folder in $hotfixSource
# - run the script
# - restart the application pool for "SDL Tridion" or restart IIS
# - test if the SDL Web CME is still working
# - clean up the .old files created by the installer

# Todo; nice to haves for this script
# - script parameters for hotfix source and verbose
# - -Whatif implementation to be able to explore the script without doing any changes
# - -Confirm to require confirmation before doing changes
# - unpack the hotfix zip, in a PowerShell 4 safe way

# Unpack the hotfix.zip and set the unzip path in $hotfixSource below. This is the only configuration parameter.
$hotfixSource = "C:\Install\SDL\Hotfix\XPM_8.1.1.3571"

# only continue if you know what you are doing...
exit


## I don't always make errors but when I do I stop
$ErrorActionPreference = "Stop"

## Set some file locations, no need to change those, those files are either coming from the Tridion installation, or from the hotfix 
$quickCheckFile = Join-Path $env:TRIDION_HOME "\web\WebUI\Editors\Safeguard\Scripts\quickcheck.js"
$quickCheckSourceFile = Join-Path $hotfixSource "quickcheck.js"

$contentScriptFile = Join-Path $env:TRIDION_HOME "\web\WebUI\Editors\Safeguard\Scripts\ContentScript.js"
$contentScriptSourceFile = Join-Path $hotfixSource "ContentScript.js"

$safeguardDllFile = Join-Path $env:TRIDION_HOME "\web\WebUI\WebRoot\bin\Tridion.Web.UI.Models.Safeguard.dll"
$safeguardDllSourceFile = Join-Path $hotfixSource "Tridion.Web.UI.Models.Safeguard.dll"

$safeguardEditorConfigFile = Join-Path $env:TRIDION_HOME "\web\WebUI\Editors\Safeguard\Configuration\SafeguardEditor.config"

$safeguardModelConfigFile = Join-Path $env:TRIDION_HOME "\web\WebUI\Models\Safeguard\Configuration\SafeguardModel.config"

$systemConfigFile = Join-Path $env:TRIDION_HOME "\web\WebUI\WebRoot\Configuration\System.config"

## Before doning any changes, check if all the files we need to touch are present
function AssertPathPrerequisite ($path)
{
    if(!(Test-Path $path))
    {
        Write-Error ("Could not find {0}" -f $path)
    }
}

AssertPathPrerequisite $hotfixSource 

AssertPathPrerequisite $quickCheckFile
AssertPathPrerequisite $quickCheckSourceFile

AssertPathPrerequisite $contentScriptFile
AssertPathPrerequisite $contentScriptSourceFile

AssertPathPrerequisite $safeguardDllFile
AssertPathPrerequisite $safeguardDllSourceFile

AssertPathPrerequisite $safeguardEditorConfigFile

AssertPathPrerequisite $safeguardModelConfigFile

AssertPathPrerequisite $systemConfigFile

# Apply the hotfix, copying a backup of each file before applying the hotfix.
Move-Item $quickCheckFile ($quickCheckFile + ".old") -Verbose
Copy-Item $quickCheckSourceFile $quickCheckFile -Verbose

Move-Item $contentScriptFile ($contentScriptFile + ".old") -Verbose
Copy-Item $contentScriptSourceFile $contentScriptFile -Verbose

Move-Item $safeguardDllFile ($safeguardDllFile + ".old") -Verbose
Copy-Item $safeguardDllSourceFile $safeguardDllFile -Verbose

Copy-Item $safeguardEditorConfigFile ($safeguardEditorConfigFile + ".old") -Verbose
[xml] $safeguardEditorConfig = Get-Content $safeguardEditorConfigFile
$safeguardEditorConfig.Configuration.settings.customconfiguration.clientconfiguration.contextURL = "http://dqm.crownpeak.com/safeguard"
$safeguardEditorConfig.Save((Resolve-Path $safeguardEditorConfigFile))

Copy-Item $SafeguardModelConfigFile ($SafeguardModelConfigFile + ".old") -Verbose
[xml] $safeguardModelConfig = Get-Content $safeguardModelConfigFile
$safeguardModelConfig.Configuration.settings.customconfiguration.ActiveStandardsServiceUrl = "https://api.crownpeak.net/dqm-cms/v1/"
$safeguardModelConfig.Save((Resolve-Path $SafeguardModelConfigFile))

Copy-Item $systemConfigFile ($systemConfigFile + ".old") -Verbose
[xml] $systemConfig = Get-Content $systemConfigFile
if(!([int] $systemConfig.Configuration.servicemodel.server.modification -gt 0))
{
    Write-Error ("Unexpeted value for Configuration\servicemodel\server\modification in {0}" -f $systemConfigFile)
}
$systemConfig.Configuration.servicemodel.server.modification = ([int] $systemConfig.Configuration.servicemodel.server.modification + 1).ToString()
$systemConfig.Save((Resolve-Path $systemConfigFile))

## Done
Write-Host "Done. Now recycle the SDL Web application pool or restart IIS"
Write-Host "Remember to clean up the .old files"