r1689 - xwiki/trunk/core/src/main/java/com/xpn/xwiki
Ludovic Dubost
ludovic at users.forge.objectweb.org
Wed Dec 6 22:50:32 CET 2006
Author: ludovic
Date: 2006-12-06 22:50:31 +0100 (Wed, 06 Dec 2006)
New Revision: 1689
Modified:
xwiki/trunk/core/src/main/java/com/xpn/xwiki/XWiki.java
Log:
XWIKI-421 New version of the fix for copying document accross wikis including attachments.
Modified: xwiki/trunk/core/src/main/java/com/xpn/xwiki/XWiki.java
===================================================================
--- xwiki/trunk/core/src/main/java/com/xpn/xwiki/XWiki.java 2006-12-06 21:41:53 UTC (rev 1688)
+++ xwiki/trunk/core/src/main/java/com/xpn/xwiki/XWiki.java 2006-12-06 21:50:31 UTC (rev 1689)
@@ -2695,6 +2695,9 @@
}
public boolean copyDocument(String docname, String targetdocname, String sourceWiki, String targetWiki, String wikilanguage, boolean reset, boolean force, XWikiContext context) throws XWikiException {
String db = context.getDatabase();
+ if (sourceWiki==null)
+ sourceWiki = db;
+
try {
if (sourceWiki != null)
context.setDatabase(sourceWiki);
@@ -2703,6 +2706,7 @@
if (log.isInfoEnabled())
log.info("Copying document: " + docname + " (default) to " + targetdocname + " on wiki " + targetWiki);
+ // Let's switch to the other database to verify if the document already exists
if (targetWiki != null)
context.setDatabase(targetWiki);
XWikiDocument tdoc = getDocument(targetdocname, context);
@@ -2716,6 +2720,10 @@
}
}
+ // Let's switch back again to the original db
+ if (sourceWiki != null)
+ context.setDatabase(sourceWiki);
+
if (wikilanguage == null) {
tdoc = sdoc.copyDocument(targetdocname, context);
// forget past versions
@@ -2762,14 +2770,11 @@
if (ttdoc != tdoc)
return false;
- //Do we have attachments in traductions? I don't think so.
- // Make sure attachments are loaded
- stdoc.loadAttachments(context);
+ // Let's switch back again to the original db
+ if (sourceWiki != null)
+ context.setDatabase(sourceWiki);
- if (docname.equals(targetdocname))
- ttdoc = (XWikiDocument) stdoc.clone();
- else
- ttdoc = stdoc.copyDocument(targetdocname, context);
+ ttdoc = stdoc.copyDocument(targetdocname, context);
// forget past versions
if (reset) {
@@ -2788,23 +2793,13 @@
txda.setId(ttdoc.getId());
getVersioningStore().saveXWikiDocArchive(txda, true, context);
}
-
}
} else {
// We want only one language in the end
- if (sourceWiki != null)
- context.setDatabase(sourceWiki);
XWikiDocument stdoc = sdoc.getTranslatedDocument(wikilanguage, context);
- if (targetWiki != null)
- context.setDatabase(targetWiki);
- // Make sure attachments are loaded
- stdoc.loadAttachments(context);
+ tdoc = stdoc.copyDocument(targetdocname, context);
- if (docname.equals(targetdocname))
- tdoc = (XWikiDocument) stdoc.clone();
- else
- tdoc = stdoc.renameDocument(targetdocname, context);
// forget language
tdoc.setDefaultLanguage(wikilanguage);
tdoc.setLanguage("");
More information about the Xwiki-notifications
mailing list