Instead of renaming subpage, it “creates” another page under subpage and then deletes the parent page.
To be clear, before the rename request, I will have the following page:
spacename.page.subpage
After the rename request, I have this:
spacename.page.subpage ← still exists in the tree layout, but when I click on it, xwiki says the page can’t be found
spacename.page.subpage.sub2
When you do that you actually perform a call to create a rename request with the following target reference: new EntityReference('sub2', $source.getType(), $source.getParent()) which in your case creates the reference: spacename.page.subpage.sub2 because the parent of spacename.page.subpage.WebHome is spacename.page.subpage.
So if you want to be sure of the location where to perform your rename I can only suggest you to manually build the target reference and use it:
It should do the trick. Also be aware that $services.refactoring.createRenameRequest is deprecated, you should probably use directly $services.refactoring.rename($source, $target).join().
The above call fails (nothing happens). I tried making the page title match the page name and that didn’t help.
If I delete the renamed page (sub2) and create it from scratch, the code to rename it does work again, but again only for the first time. My suspicion is that the velocity rename sequence is somehow tainting the page that then breaks any further renamings through velocity.
So I managed to get it working by putting “WebHome” at the end of the target address.
The next problem I’m now encountering is that if a page has a subpage and I try to rename it, it is doing the same copy-in-place thing I described in my first post.
I saw there is a “setPreserveChildren” for renameRequest API from xwiki’s github, and tried the following: