@@ -4708,6 +4708,27 @@ public void checkDeletingDocument(DocumentReference userReference, XWikiDocument
47084708 */
47094709 public void deleteDocumentVersions (XWikiDocument document , String version1 , String version2 , XWikiContext context )
47104710 throws XWikiException
4711+ {
4712+ deleteDocumentVersions (document , version1 , version2 , false , context );
4713+ }
4714+
4715+ /**
4716+ * Delete a range of versions from a document history.
4717+ *
4718+ * @param document the document from which to delete versions
4719+ * @param version1 one end of the versions range to remove
4720+ * @param version2 the other end of the versions range to remove
4721+ * @param triggeredByUser {@code true} if the API is called directly by an action from a user and checks need to
4722+ * be performed for the rollback (See: {@link #rollback(XWikiDocument, String, boolean, boolean, XWikiContext)}).
4723+ * @param context the XWiki context
4724+ * @throws XWikiException
4725+ * @since 14.10.17
4726+ * @since 15.5.3
4727+ * @since 15.8RC1
4728+ */
4729+ @ Unstable
4730+ public void deleteDocumentVersions (XWikiDocument document , String version1 , String version2 ,
4731+ boolean triggeredByUser , XWikiContext context ) throws XWikiException
47114732 {
47124733 Version v1 = new Version (version1 );
47134734 Version v2 = new Version (version2 );
@@ -4750,20 +4771,22 @@ public void deleteDocumentVersions(XWikiDocument document, String version1, Stri
47504771 .notify (new DocumentVersionRangeDeletingEvent (document .getDocumentReferenceWithLocale (),
47514772 lowerBound .toString (), upperBound .toString ()), document , context );
47524773
4753- // Update the archive
4754- context .getWiki ().getVersioningStore ().saveXWikiDocArchive (archive , true , context );
4755- // Make sure the cached document archive is updated too
4756- XWikiDocument cachedDocument =
4757- context .getWiki ().getDocument (document .getDocumentReferenceWithLocale (), context );
4758- cachedDocument .setDocumentArchive (archive );
47594774
47604775 // There are still some versions left.
47614776 // If we delete the most recent (current) version, then rollback to latest undeleted version.
4777+ // We do that right before updating the archive, in case it would cancel the action.
47624778 Version previousVersion = archive .getLatestVersion ();
47634779 if (!document .getRCSVersion ().equals (previousVersion )) {
4764- context .getWiki ().rollback (document , previousVersion .toString (), false , context );
4780+ context .getWiki ().rollback (document , previousVersion .toString (), false , triggeredByUser , context );
47654781 }
47664782
4783+ // Update the archive
4784+ context .getWiki ().getVersioningStore ().saveXWikiDocArchive (archive , true , context );
4785+ // Make sure the cached document archive is updated too
4786+ XWikiDocument cachedDocument =
4787+ context .getWiki ().getDocument (document .getDocumentReferenceWithLocale (), context );
4788+ cachedDocument .setDocumentArchive (archive );
4789+
47674790 // Notify after versions delete
47684791 getObservationManager ()
47694792 .notify (new DocumentVersionRangeDeletedEvent (document .getDocumentReferenceWithLocale (),
@@ -7569,6 +7592,25 @@ private void restoreDeletedAttachment(XWikiAttachment rolledbackAttachment, XWik
75697592 */
75707593 public XWikiDocument rollback (final XWikiDocument tdoc , String rev , boolean addRevision , XWikiContext xcontext )
75717594 throws XWikiException
7595+ {
7596+ return rollback (tdoc , rev , addRevision , false , xcontext );
7597+ }
7598+
7599+ /**
7600+ * @param tdoc the document to rollback
7601+ * @param rev the revision to rollback to
7602+ * @param addRevision true if a new revision should be created
7603+ * @param triggeredByUser {@code true} if this has been triggered by a user and a check needs to be performed
7604+ * @param xcontext the XWiki context
7605+ * @return the new document
7606+ * @throws XWikiException when failing to rollback the document
7607+ * @since 14.10.17
7608+ * @since 15.5.3
7609+ * @since 15.8RC1
7610+ */
7611+ @ Unstable
7612+ public XWikiDocument rollback (final XWikiDocument tdoc , String rev , boolean addRevision ,
7613+ boolean triggeredByUser , XWikiContext xcontext ) throws XWikiException
75727614 {
75737615 LOGGER .debug ("Rolling back [{}] to version [{}]" , tdoc , rev );
75747616
@@ -7647,6 +7689,10 @@ public XWikiDocument rollback(final XWikiDocument tdoc, String rev, boolean addR
76477689 message = localizePlainOrKey ("core.comment.rollback" , rev );
76487690 }
76497691
7692+ if (triggeredByUser ) {
7693+ checkSavingDocument (xcontext .getUserReference (), document , message , false , xcontext );
7694+ }
7695+
76507696 ObservationManager om = getObservationManager ();
76517697 if (om != null ) {
76527698 // Notify listeners about the document that is going to be rolled back.
0 commit comments