Last active
July 20, 2018 18:40
-
-
Save ssougnez/9111d7d5461efab8fe9ac84db865e655 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
Function ExtractSite { | |
Param([string]$source, [string]$destination) | |
$webConfigPath = Join-Path -Path $destination -ChildPath "Web.config" | |
$isUpgrade = Test-Path $destination; | |
if ($isUpgrade) { | |
$webConfigBackupPath = Join-Path -Path $destination -ChildPath ("Web.config.{0}.bak" -f (Get-Date).Ticks) | |
$webConfig = [xml](Get-Content ($webConfigPath) -Encoding UTF8) | |
$previousVersion = ($webConfig.configuration.appSettings.add | Where-Object { $_.key -eq "umbracoConfigurationStatus" }).value | |
$previousConnectionString = ($webConfig.configuration.connectionStrings.add | Where-Object { $_.name -eq "umbracoDbDSN" }).connectionString | |
$previousSqlProvider = ($webConfig.configuration.connectionStrings.add | Where-Object { $_.name -eq "umbracoDbDSN" }).providerName | |
$machineKey = $webConfig.configuration["system.web"].machineKey | |
Copy-Item $webConfigPath -Destination $webConfigBackupPath | |
#Waiting for locks to be released | |
Start-Sleep -Seconds 60 | |
} | |
Expand-Archive -LiteralPath (Get-Item $source).FullName -DestinationPath $destination -Force | |
if ($isUpgrade) { | |
$webConfig = [xml](Get-Content ($webConfigPath) -Encoding UTF8) | |
($webConfig.configuration.appSettings.add | Where-Object { $_.key -eq "umbracoConfigurationStatus" }).value = $previousVersion; | |
($webConfig.configuration.connectionStrings.add | Where-Object { $_.name -eq "umbracoDbDSN" }).connectionString = $previousConnectionString; | |
($webConfig.configuration.connectionStrings.add | Where-Object { $_.name -eq "umbracoDbDSN" }).providerName = $previousSqlProvider; | |
if ($null -ne $machineKey) { | |
$node = $webConfig.ImportNode($machineKey, $true); | |
$webConfig.configuration["system.web"].AppendChild($node) | Out-Null; | |
} | |
$webConfig.Save($webConfigPath) | |
} | |
Success | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment