Hi all,
I’m trying to use refactoring module to move a lot of documents form a space to another; it’s working with these 3 lines: > #set ($source = $services.model.resolveDocument(‘MyoldDoc’)) > #set ($destination = $services.model.resolveSpace(‘MynewDoc’)) > $services.refactoring.move($source, $destination).join
But it leave a backlink of the old page, and I don’t want it.
There is a way like in the rename process to avoid backlink to the old pages?
Unfortunately the move option still not working wiht these options.
I found these:
## **Move a page without the automatic correction of backlinks to target the new location**
#set ($source = $services.model.resolveDocument(‘Path.To.Source.WebHome’))
#set ($destination = **$services.model.resolveDocument**(‘Path.To.Destination.WebHome’))
#set ($moveRequest = $services.refactoring.requestFactory.createMoveRequest($source, $destination))
#set ($discard = $renameRequest.setUpdateLinks(false))
$services.refactoring.move($moveRequest)).join()
With the highligted option in line 2 the move is not working,
The move work with:
$services.model.resolveSpace(‘Path.To.New.Parent’)
as in the regular move, but still, the backlink in the old position is maintened.
I’m using it inside a velocity script, with rel. 15.10.6, if can help.
The highlighted option in line 2 is invalid velocity code and you should get an error org.apache.velocity.exception.ParseErrorException: Encountered "*" at xwiki:Space.Page[line 1, column 22].
Then, if you want backlinks updated, you need to use setUpdateLinks(true).
The example in documentation says Move a page WITHOUT the automatic correction of backlinks
HI @acotiuga,
I’ve added the two “**” before and after the function I’m using only to highlight it, I’m not using them inside the script.
What I’m trying to achieve is to move the document to another space and leave no link at the old document location, I’m hoping I won’t come out as rude, but It’s challenging to explain a circumstance this particular.
So, do you get any errors?
There’s nothing wrong with $services.model.resolveDocument(), it will obtain a DocumentReference from a String.
The quote ‘ however is unusual in the example. It should be '. Also the quotes in ‘Path.To.New.Parent’ look wrong.
Thanks @acotiuga,
I hadn’t noticed it before, and I was using the wrong options for link ($moveRequest.setUpdateLinks(false) instead of $moveRequest.setAutoRedirect(false) )
With your improvement I was able to achieve the result with this script:
{{velocity}}
## In query field you have to specify the document name or part of the name
#set ($query = "Documents to move")
## In $newspace remember to keep a dot at the end
#set ($newspace = "path.to.destination.")
## This is fixed to build the path
#set ($webhome = ".WebHome")
## I define this to specify a space where to pick the documents, otherwise documents in all spaces are moved
## If you dont want that, simply remove from the query this part: 'and doc.space like $oldspace'
#set ($oldspace = "'Path.Source%'")
#set ($hql = "select doc.fullName from XWikiDocument as doc where lower(doc.title) like lower(:title) and doc.space like $oldspace")
#set ($results = $services.query.hql($hql).bindValue("title", "%$query%").execute())
#set ($updatedCount = 0)
#if ($results.size() > 0)
#foreach ($docFullName in $results)
#set ($doc = $xwiki.getDocument($docFullName))
#set ($docTitle = $doc.getTitle())
#set ($source = $services.model.resolveDocument($doc))
#set ($destination = $services.model.resolveDocument($newspace+$docTitle+$webhome))
Moving $source -> Source to $destination -> Destination
#set ($moveRequest = $services.refactoring.requestFactory.createMoveRequest($source, $destination))
## With this option you move the document without setting up a HTTP redirect from the old location to the new location
#set ($discard = $moveRequest.setAutoRedirect(false))
## With this option you move the document without the automatic correction of backlinks to target the new location
## #set ($discard = $moveRequest.setUpdateLinks(false))
$services.refactoring.move($moveRequest)).join()
#set ($updatedCount = $updatedCount + 1)
#end
Moved documents count: $updatedCount
#else
No pages found with $query
#end
{{/velocity}}