Skip to content
Snippets Groups Projects
Commit f843e98b authored by Thomas Mortagne's avatar Thomas Mortagne
Browse files

XWIKI-21801: Duplicate versions in history of documents not based on JRCS

Co-authored-by: default avatartrrenty <trrenty@gmail.com>
parent cc864bed
No related branches found
No related tags found
No related merge requests found
......@@ -46,7 +46,6 @@
import com.xpn.xwiki.doc.XWikiAttachment;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.doc.XWikiDocumentArchive;
import com.xpn.xwiki.store.XWikiVersioningStoreInterface;
/**
* @version $Id$
......@@ -252,16 +251,6 @@ private void maybeSaveDocument() throws FilterException
xcontext.getWiki().saveDocument(document, inputDocument.getComment(), inputDocument.isMinorEdit(),
xcontext);
if (!hasJRCSHistory) {
// Not a JRCS based history document
// Explicitly update the history because the store won't do it automatically (because
// metadata/content dirty is false)
XWikiVersioningStoreInterface versioningStore = document.getVersioningStore(xcontext);
if (versioningStore != null) {
versioningStore.updateXWikiDocArchive(document, true, xcontext);
}
}
} else {
// Forget the input history to let the store do its standard job
document.setDocumentArchive((XWikiDocumentArchive) null);
......
......@@ -695,35 +695,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable
reference = reference.setWikiReference(xcontext.getWikiReference());
}
if (document.isContentDirty() || document.isMetaDataDirty()) {
document.setDate(new Date());
if (document.isContentDirty()) {
document.setContentUpdateDate(new Date());
document.setContentAuthorReference(document.getAuthorReference());
}
document.incrementVersion();
document.setContentDirty(false);
document.setMetaDataDirty(false);
if (supportRevisionStore) {
// Save the document in the document archive.
getMockVersioningStore().updateXWikiDocArchive(document, true, xcontext);
}
}
document.setNew(false);
document.setStore(getMockStore());
// Make sure the document is not restricted.
document.setRestricted(false);
XWikiDocument savedDocument = document.clone();
documents.put(document.getDocumentReferenceWithLocale(), savedDocument);
// Set the document as it's original document
savedDocument.setOriginalDocument(savedDocument.clone());
saveDocument(reference, document, xcontext);
return null;
}
......@@ -881,27 +853,6 @@ public Void answer(InvocationOnMock invocation) throws Throwable
document.setComment(StringUtils.defaultString(comment));
document.setMinorEdit(minorEdit);
if (document.isContentDirty() || document.isMetaDataDirty()) {
Date ndate = new Date();
document.setDate(ndate);
if (document.isContentDirty()) {
document.setContentUpdateDate(ndate);
DocumentAuthors authors = document.getAuthors();
authors.setContentAuthor(authors.getEffectiveMetadataAuthor());
}
document.incrementVersion();
document.setContentDirty(false);
document.setMetaDataDirty(false);
// Save the document in the document archive.
if (supportRevisionStore) {
getMockVersioningStore().updateXWikiDocArchive(document, true, xcontext);
}
}
document.setNew(false);
document.setStore(getMockStore());
XWikiDocument previousDocument = documents.get(document.getDocumentReferenceWithLocale());
if (previousDocument != null && previousDocument != document) {
......@@ -920,28 +871,28 @@ public Void answer(InvocationOnMock invocation) throws Throwable
document.setOriginalDocument(originalDocument);
}
// Make sure the document is not restricted.
document.setRestricted(false);
saveDocument(document.getDocumentReferenceWithLocale(), document, xcontext);
XWikiDocument savedDocument = document.clone();
XWikiDocument newOriginal = document.getOriginalDocument();
documents.put(document.getDocumentReferenceWithLocale(), savedDocument);
try {
document.setOriginalDocument(originalDocument);
if (isNew) {
if (notifyDocumentCreatedEvent) {
getObservationManager().notify(new DocumentCreatedEvent(document.getDocumentReference()),
document, getXWikiContext());
}
} else {
if (notifyDocumentUpdatedEvent) {
getObservationManager().notify(new DocumentUpdatedEvent(document.getDocumentReference()),
document, getXWikiContext());
if (isNew) {
getObservationManager().notify(
new DocumentCreatedEvent(document.getDocumentReference()), document,
getXWikiContext());
} else {
getObservationManager().notify(
new DocumentUpdatedEvent(document.getDocumentReference()), document,
getXWikiContext());
}
}
} finally {
document.setOriginalDocument(newOriginal);
}
// Set the document as it's original document
savedDocument.setOriginalDocument(savedDocument.clone());
return null;
}
}).when(getSpyXWiki()).saveDocument(anyXWikiDocument(), any(String.class), anyBoolean(), anyXWikiContext());
......@@ -1181,6 +1132,74 @@ public String answer(InvocationOnMock invocation) throws Throwable
}
}
private void saveDocument(DocumentReference reference, XWikiDocument document, XWikiContext xcontext)
throws XWikiException
{
boolean supportRevisionStore = this.componentManager.hasComponent(XWikiDocumentFilterUtils.class);
if (document.isContentDirty() || document.isMetaDataDirty()) {
document.setDate(new Date());
if (document.isContentDirty()) {
document.setContentUpdateDate(new Date());
DocumentAuthors authors = document.getAuthors();
authors.setContentAuthor(authors.getEffectiveMetadataAuthor());
}
document.incrementVersion();
document.setContentDirty(false);
document.setMetaDataDirty(false);
if (supportRevisionStore) {
// Save the document in the document archive.
getMockVersioningStore().updateXWikiDocArchive(document, true, xcontext);
}
} else {
if (supportRevisionStore) {
if (document.getDocumentArchive() != null) {
getMockVersioningStore().saveXWikiDocArchive(document.getDocumentArchive(), false, xcontext);
if (!containsVersion(document, document.getRCSVersion(), xcontext)) {
getMockVersioningStore().updateXWikiDocArchive(document, false, xcontext);
}
} else {
try {
document.getDocumentArchive(xcontext);
if (!containsVersion(document, document.getRCSVersion(), xcontext)) {
getMockVersioningStore().updateXWikiDocArchive(document, false, xcontext);
}
} catch (XWikiException e) {
// this is a non critical error
}
}
}
}
document.setNew(false);
document.setStore(getMockStore());
// Make sure the document is not restricted.
document.setRestricted(false);
XWikiDocument savedDocument = document.clone();
documents.put(document.getDocumentReferenceWithLocale(), savedDocument);
// Set the document as it's original document
savedDocument.setOriginalDocument(savedDocument.clone());
}
private boolean containsVersion(XWikiDocument doc, Version targetversion, XWikiContext context)
throws XWikiException
{
for (Version version : doc.getRevisions(context)) {
if (version.equals(targetversion)) {
return true;
}
}
return false;
}
protected DocumentReference resolveDocument(String documentName) throws ComponentLookupException
{
DocumentReferenceResolver<String> resolver =
......
......@@ -36,7 +36,14 @@
</entry>
<entry>
<string>syntax</string>
<null/>
<org.xwiki.rendering.syntax.Syntax>
<type>
<name>XWiki</name>
<id>xwiki</id>
<variants class="empty-list"/>
</type>
<version>2.1</version>
</org.xwiki.rendering.syntax.Syntax>
</entry>
<entry>
<string>hidden</string>
......
......@@ -36,7 +36,14 @@
</entry>
<entry>
<string>syntax</string>
<null/>
<org.xwiki.rendering.syntax.Syntax>
<type>
<name>XWiki</name>
<id>xwiki</id>
<variants class="empty-list"/>
</type>
<version>2.1</version>
</org.xwiki.rendering.syntax.Syntax>
</entry>
<entry>
<string>hidden</string>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment