SitecorePowerShell / Console

Sitecore PowerShell Extensions
https://doc.sitecorepowershell.com/
Other
114 stars 70 forks source link

Impact on the Item name in Content Tree #1316

Closed RaghuRider closed 5 months ago

RaghuRider commented 1 year ago

Implemented as part of #1316

Expected Behavior

Post rename the item name using the PowerShell script it should update in the content tree with new name without refreshing the parent item or closing and opening Please describe the expected behavior.

Actual Behavior

Displaying the OLD name in the Content Tree until user refresh the parent item in the content tree or close and opens it [again] Please refer the below code for the reference which I am using (` try {

Get context page name (old role name)

$array = $SitecoreContextItem.Paths.Path.Split("/")
$oldRoleName = $array[$array.Length - 1]
$fullRoleName = "sitecore\"+$oldRoleName

# Get input name
$name = Show-Input "Please enter page name" -DefaultValue $oldRoleName
if (!$name) {
    Exit
}

Get SitecoreContextItem Item of the Microsite.

$ContextItemID = $SitecoreContextItem.ID.ToString() $name = $name.Trim() if ($name -eq "") { Exit }

# Check if page with the new name already exists
$basePath = "master:/content/BCG/Websites/Internal Information/DesignStudios/Home/Web platform/Client Proposal/"
$content = Get-Item -Path ($basePath + $name) -ErrorAction Ignore
if ($null -ne $content) {
    Show-Alert "A page with this name already exists!"
    Exit
}

# Rename page
$elevatedUser = Get-User -Identity "sitecore\DSWPAdmin"
New-UsingBlock (New-Object Sitecore.Security.Accounts.UserSwitcher $elevatedUser) {       
    $item = Get-Item -Path $SitecoreContextItem.Paths.Path    
    $item.Editing.BeginEdit()
    $item.Name = $name    
    $item.Editing.EndEdit() 

# Rename role
$newRoleName = $name 
$newSiteName = $basePath + $name

# Get the existing role object
$oldRole = Get-Role -Name $fullRoleName
if ($oldRole) {

        # Create a new role with the new name
        $newRole = New-Role -Identity $newRoleName

        $rights = @("item:read", "item:create", "item:write", "item:delete")
        $rights  | ForEach-Object { Add-ItemAcl -Path $newSiteName -AccessRight $_ -PropagationType Any -SecurityPermission AllowAccess -Identity $newRole }        

        # Transfer members and permissions from the old role to the new role
        $members = Get-RoleMember -Identity $oldRole
        $members | ForEach-Object { Add-RoleMember -Identity $newRole -Members $_ }

        $roleToBeDeleted = Get-Role -Filter $fullRoleName
        if($roleToBeDeleted.count -gt 0)
        {
            Remove-Role -Identity $roleToBeDeleted
        }

        Write-Host "Role has been renamed from '$oldRoleName' to '$newRoleName' successfully."

} else {
    Write-Host "Role with the name '$oldRoleName' not found in Sitecore."
}

Show-Alert "As page and respective role have successfully renamed, previous URL will no longer work. Hence, please publish the microsite and then use the updated URL"

} catch { $errorMessage = $_.Exception.Message Write-Host "An error occurred: $errorMessage" }`) Please describe the actual behavior.

Steps to Reproduce the Problem

Please include the version number of SPE and Sitecore. Sitecore version is 10.1.1 and PS version is 5, Please let me know how to resolve this issue.

michaellwest commented 1 year ago

Can you provide a video or animated gif of what you experience?

RaghuRider commented 1 year ago

Hi @michaellwest ,

Please Refer the Video I had explained the issue, let me know if you need any further details

https://github.com/SitecorePowerShell/Console/assets/27493687/f44c8a21-281e-48e4-8002-6148a23a7ba9

RaghuRider commented 1 year ago

Hi @michaellwest , Please let me know, if you can help me in this to fix

michaellwest commented 1 year ago

I've seen a question and blog post related to this. I believe it would require some customizations to SPE to work.

AdamNaj commented 6 months ago

While it would not be impossible to solve - this issue creates a lot of edge cases.

I suggest we close this issue for now and if there is more interest, it can get reopened again.

AdamNaj commented 5 months ago

Can now be done using the functionality implemented in #1340