use of org.xwiki.refactoring.batch.BatchOperationExecutor in project xwiki-platform by xwiki.
the class DeleteVersionsAction method action.
@Override
public boolean action(XWikiContext context) throws XWikiException {
DeleteVersionsForm form = (DeleteVersionsForm) context.getForm();
if (!form.isConfirmed() || !csrfTokenCheck(context)) {
return true;
}
XWikiDocument doc = context.getDoc();
String language = form.getLanguage();
XWikiDocument tdoc = doc.getTranslatedDocument(language, context);
XWikiDocumentArchive archive = tdoc.getDocumentArchive(context);
// Get the versions
Version[] versions = getVersionsFromForm(form, archive);
Version v1 = versions[0];
Version v2 = versions[1];
if (v1 != null && v2 != null) {
// Remove the versions
archive.removeVersions(v1, v2, context);
context.getWiki().getVersioningStore().saveXWikiDocArchive(archive, true, context);
tdoc.setDocumentArchive(archive);
// Is this the last remaining version? If so, then recycle the document.
if (archive.getLatestVersion() == null) {
// Wrap the work as a batch operation.
BatchOperationExecutor batchOperationExecutor = Utils.getComponent(BatchOperationExecutor.class);
batchOperationExecutor.execute(() -> {
if (StringUtils.isEmpty(language) || language.equals(doc.getDefaultLanguage())) {
context.getWiki().deleteAllDocuments(doc, context);
} else {
// Only delete the translation
context.getWiki().deleteDocument(tdoc, context);
}
});
} else {
// If we delete the most recent (current) version, then rollback to latest undeleted version.
if (!tdoc.getRCSVersion().equals(archive.getLatestVersion())) {
XWikiDocument newdoc = archive.loadDocument(archive.getLatestVersion(), context);
// Reset the document reference, since the one taken from the archive might be wrong (old name from
// before a rename)
newdoc.setDocumentReference(tdoc.getDocumentReference());
// Get rid of objects that don't exist in new version
newdoc.addXObjectsToRemoveFromVersion(tdoc);
// Make sure we don't create a new rev!
newdoc.setMetaDataDirty(false);
newdoc.setContentDirty(false);
// Make sure the previous current document is seen as original document of
// the new current document for comparisons
newdoc.setOriginalDocument(tdoc.getOriginalDocument());
// Update the database with what is now the current document
context.getWiki().saveDocument(newdoc, newdoc.getComment(), context);
context.setDoc(newdoc);
}
}
}
sendRedirect(context);
return false;
}
use of org.xwiki.refactoring.batch.BatchOperationExecutor in project xwiki-platform by xwiki.
the class XWiki method deleteAllDocuments.
public void deleteAllDocuments(XWikiDocument doc, boolean toTrash, XWikiContext context) throws XWikiException {
// Wrap the work as a batch operation.
BatchOperationExecutor batchOperationExecutor = Utils.getComponent(BatchOperationExecutor.class);
batchOperationExecutor.execute(() -> {
// Delete all translation documents
for (Locale locale : doc.getTranslationLocales(context)) {
XWikiDocument tdoc = doc.getTranslatedDocument(locale, context);
deleteDocument(tdoc, toTrash, context);
}
// Delete the default document
deleteDocument(doc, toTrash, context);
});
}
Aggregations