Console icon indicating copy to clipboard operation
Console copied to clipboard

Impact on the Item name in Content Tree

Open RaghuRider opened this issue 2 years ago • 5 comments

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.

  • [ ] Tested issue with clean install of Sitecore and the latest available version of SPE.

  • [ ] Asked questions on the Sitecore Slack Chat channel.

  • [ ] Reviewed questions and answers on the Sitecore Stack Exchange.

RaghuRider avatar Sep 12 '23 12:09 RaghuRider

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

michaellwest avatar Sep 12 '23 12:09 michaellwest

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 avatar Sep 12 '23 13:09 RaghuRider

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

RaghuRider avatar Sep 14 '23 05:09 RaghuRider

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

michaellwest avatar Sep 14 '23 16:09 michaellwest

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

  • What if it's not only the clicked item?
  • What if it concerns Parent item?
  • What if many items need to be refreshed?
  • What if it's not called from Content Editor?

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

AdamNaj avatar May 09 '24 22:05 AdamNaj

Can now be done using the functionality implemented in #1340

AdamNaj avatar May 30 '24 21:05 AdamNaj