Rollback A Document

Last modified by Vincent Massol on 2026/08/05 17:15

cogShows how to programmatically rollback a document to the last but one version
TypeSnippet
Category
Developed by

Vincent Massol

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Table of contents

Description

Information

Requires Programming Rights to execute

{{velocity}}
#set ($rollbackDoc = $xwiki.getDocument("Sandbox.WebHome"))
##-----------------------
## Find the last but one revision
##-----------------------
#set ($criteria = $xwiki.criteriaService.revisionCriteriaFactory.createRevisionCriteria())
#set ($range = $xwiki.criteriaService.rangeFactory.createTailRange(2))
$criteria.setRange($range)
$criteria.setIncludeMinorVersions(true)
#set ($revision = $rollbackDoc.getRevisions($criteria).get(0))
##-----------------------
## Perform the rollback
##-----------------------
$xwiki.getXWiki().rollback($rollbackDoc.document, $revision, $context.context)
{{/velocity}}

Get Connected