Created
July 20, 2023 16:37
-
-
Save marcelgruber/2bfb04326269af5c7d5d03c059b50431 to your computer and use it in GitHub Desktop.
Database Refresh Post Step For Item Field Value Updates With Environment Selector
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
$options = @{ | |
"DEV"="DEV" | |
"STAGE"="STAGE" | |
} | |
$props = @{ | |
Parameters = @( | |
@{Name="selectedOption"; Title="Choose an environment"; Options=$options} | |
) | |
Title = "Environment selector" | |
Description = "Restore values for which environment?" | |
Width = 300 | |
Height = 300 | |
ShowHints = $false | |
} | |
$result = Read-Variable @props | |
if($result -ne "ok") | |
{ | |
Exit | |
} | |
Write-Host "Selected environment: $($selectedOption)" | |
Write-Host "" | |
$isDev = $selectedOption -eq "DEV" | |
$Restorable = @( | |
@{ | |
"fPath"="master://sitecore/content/path/to/item"; | |
"field"="FieldName"; | |
"updatedVal"= | |
if ($isDev) | |
{"dev value"} | |
else | |
{"stage value"}; | |
}, | |
@{ | |
"fPath"="master://sitecore/content/path/to/item2"; | |
"field"="FieldName"; | |
"updatedVal"= | |
if ($isDev) | |
{"dev value"} | |
else | |
{"stage value"}; | |
}) | |
foreach ($restore in $Restorable){ | |
$item = Get-Item -Path $restore.fPath -language en | |
Write-Host "Updating item: $($item.ID) $($restore.fPath)" | |
Write-Host "Updating field: $($restore.field)" | |
Write-Host "--" | |
Write-Host "From:" | |
Write-Host "$($item[$($restore.field)])" | |
Write-Host "" | |
$item.Editing.BeginEdit() | |
$item["$($restore.field)"] = "$($restore.updatedVal)" | |
$item.Editing.EndEdit() | Out-Null | |
Write-Host "To:" | |
Write-Host "$($item[$($restore.field)])" | |
Write-Host "----------------------------------------" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment