Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.plugin.packaging.DocumentInfo;
import com.xpn.xwiki.plugin.packaging.Package;
import com.xpn.xwiki.plugin.packaging.PackageException;

import one.util.streamex.StreamEx;

Expand Down Expand Up @@ -119,12 +120,15 @@ private void importDocs(Path path, boolean force) throws XWikiException {
var skipAll = true;
for (DocumentInfo docInfo : importer.getFiles()) {
var docRef = modelUtils.resolveRef(docInfo.getFullName(), DocumentReference.class);
var skip = !force && modelAccess.exists(docRef);
var skip = !force && modelAccess.existsLang(docRef, docInfo.getLanguage());
docInfo.setAction(skip ? ACTION_SKIP : ACTION_OVERWRITE);
skipAll &= skip;
}
if (!skipAll) {
importer.install(getXContext());
int status = importer.install(getXContext());
if ((status == INSTALL_ERROR) || (status == INSTALL_IMPOSSIBLE)) {
throw new PackageException(0, "Failed to import disk docs from [" + path + "]");
}
LOGGER.debug("imported [{}]", path);
} else {
LOGGER.debug("skipped import [{}], nothing to do", path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static com.celements.execution.XWikiExecutionProp.*;
import static com.google.common.base.Preconditions.*;
import static com.xpn.xwiki.XWikiConstant.*;
import static com.xpn.xwiki.user.api.XWikiRightService.*;

import java.util.concurrent.CompletableFuture;
Expand All @@ -24,12 +25,11 @@
import org.xwiki.context.ExecutionContext;
import org.xwiki.context.ExecutionContextException;
import org.xwiki.context.ExecutionContextManager;
import org.xwiki.model.reference.WikiReference;

import com.celements.init.update.WikiUpdater;
import com.celements.wiki.WikiCreator;
import com.celements.wiki.exception.WikiCreationException;
import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiConfigSource;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.internal.XWikiExecutionContextInitializer;
import com.xpn.xwiki.store.XWikiCacheStoreInterface;
Expand All @@ -54,8 +54,8 @@ public class CelementsBootstrap implements ApplicationListener<CelementsStartedE
private final ExecutionContextManager executionManager;
private final ComponentManager componentManager;
private final XWikiHibernateStore hibernateStore;
private final XWikiConfigSource xwikiCfg;
private final WikiCreator wikiCreator;
private final WikiUpdater wikiUpdater;
private final ListableBeanFactory beanFactory;

@Inject
Expand All @@ -65,16 +65,16 @@ public CelementsBootstrap(
ExecutionContextManager executionManager,
ComponentManager componentManager,
@Named("hibernate") XWikiStoreInterface hibernateStore,
XWikiConfigSource xwikiCfg,
WikiCreator wikiCreator,
WikiUpdater wikiUpdater,
ListableBeanFactory beanFactory) {
this.servletContext = servletContext;
this.execution = execution;
this.executionManager = executionManager;
this.componentManager = componentManager;
this.hibernateStore = (XWikiHibernateStore) hibernateStore;
this.xwikiCfg = xwikiCfg;
this.wikiCreator = wikiCreator;
this.wikiUpdater = wikiUpdater;
this.beanFactory = beanFactory;
}

Expand Down Expand Up @@ -109,7 +109,7 @@ private XWiki bootstrapXWiki()
ExecutionContext eCtx = createExecutionContext();
LOGGER.debug("initialising hibernate...");
hibernateStore.initHibernate();
var postActions = wikiCreator.ensureWikiDeferred(getMainWikiRef());
var postActions = wikiCreator.ensureWikiDeferred(MAIN_WIKI);
LOGGER.debug("initialising ExecutionContext...");
executionManager.initialize(eCtx);
LOGGER.debug("initialising XWiki...");
Expand All @@ -121,9 +121,7 @@ private XWiki bootstrapXWiki()
LOGGER.debug("post main wiki creation action...");
action.run();
LOGGER.debug("flushing store caches...");
// prevents borked XWikiPreferences
beanFactory.getBeansOfType(XWikiCacheStoreInterface.class).values()
.forEach(XWikiCacheStoreInterface::flushCache);
flushCacheStores();
});
return xwiki;
}
Expand All @@ -137,8 +135,11 @@ public ExecutionContext createExecutionContext() {
return executionCtx;
}

WikiReference getMainWikiRef() {
return new WikiReference(xwikiCfg.getMainWikiName());
// prevents borked XWikiPreferences
private void flushCacheStores() {
wikiUpdater.awaitCompletion(MAIN_WIKI); // don't flush caches while wiki updaters still operate
beanFactory.getBeansOfType(XWikiCacheStoreInterface.class).values()
.forEach(XWikiCacheStoreInterface::flushCache);
}

public class CelementsBootstrapException extends RuntimeException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -66,6 +67,7 @@
import com.xpn.xwiki.web.Utils;

import net.sf.json.JSONObject;
import one.util.streamex.StreamEx;

public class Package {

Expand Down Expand Up @@ -186,7 +188,7 @@ public void setPreserveVersion(boolean preserveVersion) {
}

public List<DocumentInfo> getFiles() {
return this.files;
return files;
}

public List<DocumentInfo> getCustomMappingFiles() {
Expand Down Expand Up @@ -242,7 +244,7 @@ public boolean add(XWikiDocument doc, int defaultAction, XWikiContext context)
return false;
}
LOG.debug("add - doc [{}:{}]", doc.getFullName(), doc.getLanguage());
for (DocumentInfo di : this.files) {
for (DocumentInfo di : getFiles()) {
if (di.getFullName().equals(doc.getFullName())
&& (di.getLanguage().equals(doc.getLanguage()))) {
if (defaultAction != DocumentInfo.ACTION_NOT_DEFINED) {
Expand All @@ -263,7 +265,7 @@ public boolean add(XWikiDocument doc, int defaultAction, XWikiContext context)

DocumentInfo docinfo = new DocumentInfo(doc, checkEditRights);
docinfo.setAction(defaultAction);
this.files.add(docinfo);
getFiles().add(docinfo);
BaseClass bclass = doc.getxWikiClass();
if (bclass.getFieldList().size() > 0) {
this.classFiles.add(docinfo);
Expand Down Expand Up @@ -333,12 +335,12 @@ public void filter(XWikiDocument doc, XWikiContext context) throws ExcludeDocume
}

public String export(OutputStream os, XWikiContext context) throws IOException, XWikiException {
if (this.files.size() == 0) {
if (getFiles().size() == 0) {
return "No Selected file";
}

ZipOutputStream zos = new ZipOutputStream(os);
for (DocumentInfo docinfo : this.files) {
for (DocumentInfo docinfo : getFiles()) {
XWikiDocument doc = docinfo.getDoc();
addToZip(doc, zos, this.withVersions, context);
}
Expand All @@ -357,7 +359,7 @@ public String exportToDir(File dir, XWikiContext context) throws IOException, XW
"Error creating directory {0}", null, args);
}

for (DocumentInfo docinfo : this.files) {
for (DocumentInfo docinfo : getFiles()) {
XWikiDocument doc = docinfo.getDoc();
addToDir(doc, dir, this.withVersions, context);
}
Expand Down Expand Up @@ -524,10 +526,7 @@ private void updateFileInfos(Document xml) {
}

private void setDocumentDefaultAction(String docName, String language, int defaultAction) {
if (this.files == null) {
return;
}
for (DocumentInfo docInfo : this.files) {
for (DocumentInfo docInfo : getFiles()) {
if (docInfo.getFullName().equals(docName) && docInfo.getLanguage().equals(language)) {
docInfo.setAction(defaultAction);
return;
Expand All @@ -542,12 +541,12 @@ public int testInstall(boolean isAdmin, XWikiContext context) {

int result = DocumentInfo.INSTALL_IMPOSSIBLE;
try {
if (this.files.size() == 0) {
if (getFiles().size() == 0) {
return result;
}

result = this.files.get(0).testInstall(isAdmin, context);
for (DocumentInfo docInfo : this.files) {
result = getFiles().get(0).testInstall(isAdmin, context);
for (DocumentInfo docInfo : getFiles()) {
int res = docInfo.testInstall(isAdmin, context);
if (res < result) {
result = res;
Expand Down Expand Up @@ -598,7 +597,9 @@ public int install(XWikiContext context) throws XWikiException {
}

// Install the remaining documents (without class definitions).
for (DocumentInfo docInfo : this.files) {
// sorting: ensure translations are always installed last
for (DocumentInfo docInfo : StreamEx.of(getFiles()).sorted(Comparator
.comparing((DocumentInfo doc) -> !doc.getLanguage().isEmpty()))) {
if (!this.classFiles.contains(docInfo)
&& (installDocument(docInfo, isAdmin, backup, context) == DocumentInfo.INSTALL_ERROR)) {
status = DocumentInfo.INSTALL_ERROR;
Expand Down Expand Up @@ -942,7 +943,7 @@ public void toXML(XMLWriter wr) throws IOException {
Element elfiles = new DOMElement("files");
wr.writeOpen(elfiles);

for (DocumentInfo docInfo : this.files) {
for (DocumentInfo docInfo : getFiles()) {
Element elfile = new DOMElement("file");
elfile.addAttribute("defaultAction", String.valueOf(docInfo.getAction()));
elfile.addAttribute("language", String.valueOf(docInfo.getLanguage()));
Expand Down Expand Up @@ -1264,7 +1265,7 @@ public JSONObject toJSON(XWikiContext wikiContext) {

Map<String, Map<String, List<Map<String, String>>>> files = new HashMap<>();

for (DocumentInfo docInfo : this.files) {
for (DocumentInfo docInfo : getFiles()) {
Map<String, String> fileInfos = new HashMap<>();
fileInfos.put("defaultAction", String.valueOf(docInfo.getAction()));
fileInfos.put("language", String.valueOf(docInfo.getLanguage()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@ public final void run() {
try {
initExecutionContext();
runInternal();
} catch (Exception e) {
} catch (ExecutionContextException e) {
logger.error("Failed to initialize execution context", e);
throw new RuntimeException(e);
} catch (Exception e) {
logger.error("execution failed", e);
throw new RuntimeException(e);
} finally {
cleanupExecutionContext();
}
Expand Down