Console
Console copied to clipboard
Rename-Item do not take info account language version
Using cmldet in a following way result in creating new language versions
$item | Rename-Item -Newname "OK"
where $item is only version other than en
Expected Behavior
No extensive language versions should be created
Actual Behavior
If you rename item with da version you will get extra en version
Steps to Reproduce the Problem
- add Danish language to the system
- create new item named da under
/sitecore/content/Home - invoke script
Get-Item -Path '/sitecore/content/Home/da' -Language "da" | Rename-Item -NewName "da1"
@alan-null Are there other commands that do not properly handle the language?
@michaellwest I don't know. I haven't checked
It feels a bit like the PR is making assumptions, like:
- The rename happens right after the item is retrieved (As the value requires wrapping to happen to remember the language)
- Multiple consecutive renames may not be on the items with the same languages missing, e.g. if they are coming from a some table.
- The value is never wiped.
But based on the case here... we're modifying Name which is version independent, which means we need ANY existing version to avoid the problem. Hence the solution provided just looks for the first existing version and does the operation on that.
Additionally found that the same problem may exist in Move-Item and Transfer-Item even though I didn't necessarily do much work to reproduce those.
Testing Script for Rename-Item:
$name1="Home2"
$name2="Home1"
$exoticLanguage = "pl-PL"
if(Test-Path "master:\content\$name1"){
$sourcePath = "master:\content\$name1"
$newName = $name2
$destinationPath = "master:\content\$name2"
} else {
$sourcePath = "master:\content\$name2"
$newName = $name1
$destinationPath = "master:\content\$name1"
if(!(Test-Path "master:\content\$name2")){
New-Item $sourcePath -Language $exoticLanguage -ItemType "Sample/Sample Item" | Out-Null
}
}
Remove-ItemVersion -Path $sourcePath -Language "en" -Version "*"
Get-Item $sourcePath -Language $exoticLanguage | Rename-Item -Newname $newName
Get-Item $destinationPath -Language * -Version *