Created
June 16, 2014 20:19
-
-
Save dougludlow/0973862cfc2bac196052 to your computer and use it in GitHub Desktop.
Update the EmbeddedContent package on mulitple Umbraco sites
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
function Update-EmbeddedContent { | |
Param([string]$site) | |
# Replace DLL | |
$source = "Updated\bin\TheFarm.Umbraco.EmbeddedContent.dll" | |
$assembly = (Join-Path $site "bin\TheFarm.Umbraco.EmbeddedContent.dll") | |
Remove-Item $assembly | |
Copy-Item $source -Destination $assembly | |
# Replace user control | |
# NVM, the user control is the same | |
# Remove old handlers from web.config | |
$configPath = (Join-Path $site "web.config") | |
[xml]$config = Get-Content $configPath | |
$xpath = "//handlers/*[@name='UmbracoNodeName'] | //httpHandlers/*[@path='umbraco/REST/umbraconodename']" | |
$config.SelectNodes($xpath) | ForEach-Object { | |
$_.ParentNode.RemoveChild($_) | Out-Null | |
} | |
$config.Save($configPath) | |
# Update installedPackages.config | |
$newPackagePath = "Updated\App_Data\packages\installed\installedPackages.config" | |
$packagesPath = (Join-Path $site "App_Data\packages\installed\installedPackages.config") | |
[xml]$newPackages = Get-Content $newPackagePath | |
[xml]$packages = Get-Content $packagesPath | |
$id = ([int]$packages.SelectSingleNode("//package[last()]").Attributes["id"].Value) + 1 | |
$embeddedXPath = "//package[@name='Embedded Content']" | |
$node = $packages.SelectSingleNode($embeddedXPath) | |
If ($node -ne $null) { | |
$node.ParentNode.RemoveChild($node) | Out-Null | |
} | |
$newNode = $newPackages.SelectSingleNode($embeddedXPath) | |
$newNode.Attributes["id"].Value = $id | |
$packagesNode = $packages.SelectSingleNode("//packages") | |
$packagesNode.AppendChild($packagesNode.OwnerDocument.ImportNode($newNode, $true)) | Out-Null | |
$packages.Save($packagesPath) | |
} | |
function Get-EmbeddedContentVersion { | |
Param([string]$site) | |
$assembly = (Join-Path $site "\bin\TheFarm.Umbraco.EmbeddedContent.dll") | |
If (Test-Path $assembly) { | |
return [System.Diagnostics.FileVersionInfo]::GetVersionInfo($assembly).ProductVersion | |
} | |
return $null | |
} | |
function Test-EmbeddedContentOutdated { | |
Param([string]$site) | |
$version = Get-EmbeddedContentVersion $site | |
If (($version -ne $null) -and ($version -ne "1.2.4")) { | |
return $true | |
} | |
return $false | |
} | |
function Update-EmbeddedContentForAllSitesIn { | |
Param([string]$inetpub) | |
Get-ChildItem $inetpub -Directory | Foreach-Object { | |
$site = $_.FullName | |
If (Test-EmbeddedContentOutdated $site) { | |
Update-EmbeddedContent $site | |
} | |
} | |
} | |
function Get-SitesWhereEmbeddedContentNeedsToBeUdated { | |
Param([string]$inetpub) | |
$table = @{Expression={Get-EmbeddedContentVersion $_.FullName};Label="Embedded Content Version"}, @{Expression={$_.FullName};Label="Site Path"} | |
Get-ChildItem $inetpub -Directory | Where-Object { ((Get-EmbeddedContentVersion $_.FullName) -ne $null) -and ((Get-EmbeddedContentVersion $_.FullName) -ne "1.2.4") } | Format-Table $table | |
} |
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
TestFixture "UpdateTest" { | |
$temp = [System.Guid]::NewGuid().ToString() | |
$site = (Join-Path $TestScriptPath $Temp) | |
Set-Location $TestScriptPath | |
TestSetup { | |
New-Item -type Directory -name $temp | |
Copy-Item $TestScriptPath\Target\* -Destination $TestScriptPath\$temp -Recurse | |
} | |
TestCase "ChecksIfOutdatedCorrectly" { | |
. $TestScriptPath\Update.ps1 | |
Test-EmbeddedContentOutdated (Join-Path $TestScriptPath $temp)| Should Be $true | |
Test-EmbeddedContentOutdated (Join-Path $TestScriptPath "Updated") | Should Be $false | |
} | |
TestCase "AssemblyIsReplaced" { | |
. $TestScriptPath\Update.ps1 | |
$assembly = (Join-Path $site "\bin\TheFarm.Umbraco.EmbeddedContent.dll") | |
Test-Path $assembly | Should Be $true | |
[System.Diagnostics.FileVersionInfo]::GetVersionInfo($assembly).ProductVersion | Should Not Be "1.2.4" | |
Update-EmbeddedContent $site | |
Test-Path $assembly | Should Be $true | |
[System.Diagnostics.FileVersionInfo]::GetVersionInfo($assembly).ProductVersion | Should Be "1.2.4" | |
} | |
TestCase "HandlersRemovedFromWebConfig" { | |
. $TestScriptPath\Update.ps1 | |
[xml]$config = Get-Content (Join-Path $site "web.config") | |
$xpath = "//handlers/*[@name='UmbracoNodeName'] | //httpHandlers/*[@path='umbraco/REST/umbraconodename']" | |
$config.SelectNodes($xpath).Count | Should Be 3 | |
Update-EmbeddedContent $site | |
[xml]$config = Get-Content (Join-Path $site "web.config") | |
$config.SelectNodes($xpath).Count | Should Be 0 | |
} | |
TestCase "PackageUpdatedInInstalledPackagesConfig" { | |
. $TestScriptPath\Update.ps1 | |
$packagesPath = (Join-Path $site "App_Data\packages\installed\installedPackages.config") | |
[xml]$packages = Get-Content $packagesPath | |
$embeddedXPath = "//package[@name='Embedded Content']" | |
$packages.SelectNodes($embeddedXPath).Count | Should Be 1 | |
$packages.SelectSingleNode($embeddedXPath).Attributes["version"].Value | Should Not Be "1.2.4" | |
Update-EmbeddedContent $site | |
[xml]$packages = Get-Content $packagesPath | |
$packages.SelectNodes($embeddedXPath).Count | Should Be 1 | |
$packages.SelectSingleNode($embeddedXPath).Attributes["id"].Value | Should Be "24" | |
$packages.SelectSingleNode($embeddedXPath).Attributes["version"].Value | Should Be "1.2.4" | |
} | |
TestTearDown { | |
Remove-Item -Recurse -Force $TestScriptPath\$temp | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment