use of org.suigeneris.jrcs.rcs.Version 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.suigeneris.jrcs.rcs.Version in project xwiki-platform by xwiki.
the class XWikiHibernateVersioningStore method getXWikiDocVersions.
@Override
public Version[] getXWikiDocVersions(XWikiDocument doc, XWikiContext context) throws XWikiException {
try {
XWikiDocumentArchive archive = getXWikiDocumentArchive(doc, context);
if (archive == null) {
return new Version[0];
}
Collection<XWikiRCSNodeInfo> nodes = archive.getNodes();
Version[] versions = new Version[nodes.size()];
Iterator<XWikiRCSNodeInfo> it = nodes.iterator();
for (int i = 0; i < versions.length; i++) {
XWikiRCSNodeInfo node = it.next();
versions[versions.length - 1 - i] = node.getId().getVersion();
}
return versions;
} catch (Exception e) {
Object[] args = { doc.getFullName() };
throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_READING_REVISIONS, "Exception while reading document {0} revisions", e, args);
}
}
use of org.suigeneris.jrcs.rcs.Version in project xwiki-platform by xwiki.
the class XWikiHibernateVersioningStore method loadXWikiDoc.
@Override
public XWikiDocument loadXWikiDoc(XWikiDocument basedoc, String sversion, XWikiContext inputxcontext) throws XWikiException {
XWikiContext context = getExecutionXContext(inputxcontext, true);
try {
XWikiDocumentArchive archive = getXWikiDocumentArchive(basedoc, context);
Version version = new Version(sversion);
XWikiDocument doc = archive.loadDocument(version, context);
if (doc == null) {
Object[] args = { basedoc.getDocumentReferenceWithLocale(), version.toString() };
throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_UNEXISTANT_VERSION, "Version {1} does not exist while reading document {0}", null, args);
}
// Make sure the document has the same name
// as the new document (in case there was a name change
// FIXME: is this really needed ?
doc.setDocumentReference(basedoc.getDocumentReference());
doc.setStore(basedoc.getStore());
return doc;
} finally {
restoreExecutionXContext();
}
}
use of org.suigeneris.jrcs.rcs.Version in project xwiki-platform by xwiki.
the class XWikiDocument method getLastChanges.
public List<Delta> getLastChanges(XWikiContext context) throws XWikiException, DifferentiationFailedException {
Version version = getRCSVersion();
try {
String prev = getDocumentArchive(context).getPrevVersion(version).toString();
XWikiDocument prevDoc = context.getWiki().getDocument(this, prev, context);
return getDeltas(Diff.diff(ToString.stringToArray(prevDoc.getContent()), ToString.stringToArray(getContent())));
} catch (Exception ex) {
LOGGER.debug("Exception getting differences from previous version: " + ex.getMessage());
}
return new ArrayList<Delta>();
}
use of org.suigeneris.jrcs.rcs.Version in project xwiki-platform by xwiki.
the class XWikiDocument method getRevisions.
/**
* Get document versions matching criterias like author, minimum creation date, etc.
*
* @param criteria criteria used to match versions
* @return a list of matching versions
*/
public List<String> getRevisions(RevisionCriteria criteria, XWikiContext context) throws XWikiException {
List<String> results = new ArrayList<String>();
Version[] revisions = getRevisions(context);
XWikiRCSNodeInfo nextNodeinfo = null;
XWikiRCSNodeInfo nodeinfo;
for (Version revision : revisions) {
nodeinfo = nextNodeinfo;
nextNodeinfo = getRevisionInfo(revision.toString(), context);
if (nodeinfo == null) {
continue;
}
// Minor/Major version matching
if (criteria.getIncludeMinorVersions() || !nextNodeinfo.isMinorEdit()) {
// Author matching
if (criteria.getAuthor().equals("") || criteria.getAuthor().equals(nodeinfo.getAuthor())) {
// Date range matching
Date versionDate = nodeinfo.getDate();
if (versionDate.after(criteria.getMinDate()) && versionDate.before(criteria.getMaxDate())) {
results.add(nodeinfo.getVersion().toString());
}
}
}
}
nodeinfo = nextNodeinfo;
if (nodeinfo != null) {
if (criteria.getAuthor().equals("") || criteria.getAuthor().equals(nodeinfo.getAuthor())) {
// Date range matching
Date versionDate = nodeinfo.getDate();
if (versionDate.after(criteria.getMinDate()) && versionDate.before(criteria.getMaxDate())) {
results.add(nodeinfo.getVersion().toString());
}
}
}
return criteria.getRange().subList(results);
}
Aggregations