Rename Space
Last modified by Vincent Massol on 2021/03/18 11:28
Rename all pages in a space |
Type | Snippet |
Category | |
Developed by | |
Rating | |
License | GNU Lesser General Public License 2.1 |
Table of contents
Description
If you have XWiki 7.2M1+ you just need to use the Refactoring Script service.
For example:
{{velocity}}
#set ($source = $services.model.resolveSpace('Path.To.Source'))
#set ($destination = $services.model.resolveSpace('Path.To.New.Parent'))
$services.refactoring.move($source, $destination).join()
{{/velocity}}
#set ($source = $services.model.resolveSpace('Path.To.Source'))
#set ($destination = $services.model.resolveSpace('Path.To.New.Parent'))
$services.refactoring.move($source, $destination).join()
{{/velocity}}
Old XWiki Versions
If you're on XWiki < 7.2M1 read on...
Code in XWiki Syntax 2.0
{{velocity}}
= Rename space =
#if($request.action == 'rename')
#if($request.from && $request.to)
Renamings:
#foreach($item in $xwiki.getSpaceDocsName($request.from))
#set ($fromReference = $services.model.createDocumentReference("", $request.from, $item))
#set ($toReference = $services.model.createDocumentReference("", $request.to, $item))
* Renamed [$services.model.serialize($fromReference)] to [[$services.model.serialize($toReference)]]
#set($ok = $xwiki.getDocument($fromReference).rename($toReference))
#end
#end
#end
{{html wiki='true'}}
<form action="$doc.getURL()" method="post" class="xform third">
<input type="hidden" name="action" value="rename" />
<div class="xform">
<dl>
<dt>Source space:</dt>
<dd><select name="from">
<option value="">please select</option>
#foreach($space in $xwiki.getSpaces())
<option value="$escapetool.xml($space)">$escapetool.xml($space)</option>
#end
</select></dd>
<dt>New space:</dt>
<dd><input type="text" name="to" value=""/></dd>
</dl>
</div>
<div class="buttons">
<input type="submit" value="Rename" class="button" />
</div>
</form>
{{/html}}
{{/velocity}}
= Rename space =
#if($request.action == 'rename')
#if($request.from && $request.to)
Renamings:
#foreach($item in $xwiki.getSpaceDocsName($request.from))
#set ($fromReference = $services.model.createDocumentReference("", $request.from, $item))
#set ($toReference = $services.model.createDocumentReference("", $request.to, $item))
* Renamed [$services.model.serialize($fromReference)] to [[$services.model.serialize($toReference)]]
#set($ok = $xwiki.getDocument($fromReference).rename($toReference))
#end
#end
#end
{{html wiki='true'}}
<form action="$doc.getURL()" method="post" class="xform third">
<input type="hidden" name="action" value="rename" />
<div class="xform">
<dl>
<dt>Source space:</dt>
<dd><select name="from">
<option value="">please select</option>
#foreach($space in $xwiki.getSpaces())
<option value="$escapetool.xml($space)">$escapetool.xml($space)</option>
#end
</select></dd>
<dt>New space:</dt>
<dd><input type="text" name="to" value=""/></dd>
</dl>
</div>
<div class="buttons">
<input type="submit" value="Rename" class="button" />
</div>
</form>
{{/html}}
{{/velocity}}
Result
Screen copy of the result page with the velocity Code in XWiki Syntax 2.0: