}
}
private static void migrateDesign(Element contentDBElement, ContentStore cs, WGAConfiguration config, String configPath, DesignSource fsDesignSource, MigrationResult migrationResult) {
Element designElement = contentDBElement.element("design");
DesignConfiguration oldConfig = new DesignConfiguration(designElement);
if (designElement != null) {
if (oldConfig.getProvider().equals("sync")) {
String designLocation = oldConfig.getDetailInfo();
if (designLocation != null && !designLocation.trim().equals("")) {
File designDir = new File(configPath, designLocation);
String defaultFSDesignRoot = System.getProperty(WGAConfiguration.SYSPROP_DESIGN_ROOT);
File defaultFSSourceDir = null;
if (defaultFSDesignRoot != null && (defaultFSDesignRoot.startsWith("/") || defaultFSDesignRoot.contains(":"))) {
// default fsDesignRoot is absolute
defaultFSSourceDir = new File(defaultFSDesignRoot);
} else if (defaultFSDesignRoot != null) {
// default fsDesignRoot is relative
defaultFSSourceDir = new File(configPath, defaultFSDesignRoot);
} else {
// default fsDesignRoot is not set
defaultFSSourceDir = new File(configPath, WGAConfiguration.DEFAULT_DESIGNROOT);
}
if (!designDir.exists() && !designLocation.startsWith("/") && !designLocation.contains(":")) {
// if design location is relativ
// try to find designDir in default FSSource
designDir = new File(defaultFSSourceDir, designDir.getName());
}
if (!designDir.exists()) {
migrationResult.logWarning("Unable to migrate design of content store '" + cs.getKey() + "'. Cannot find design directory '" + designLocation + "'.");
return;
}
Design design;
// Look if the design dir is at the proposed position under
// default FSSource
if (designDir.getParentFile().equals(defaultFSSourceDir)) {
design = new Design(Constants.DESIGNCOL_FILESYSTEM, designDir.getName());
}
else {
// The design is not at the default position. We
// register it as "additional dir"
int idx = 1;
String addDirName = null;
String otherDir = null;
idx = 0;
do {
idx++;
addDirName = designDir.getName() + idx;
otherDir = fsDesignSource.getOptions().get("additionaldir." + addDirName);
} while (otherDir != null);
fsDesignSource.getOptions().put("additionaldir." + addDirName, designDir.getAbsolutePath());
design = new Design(fsDesignSource.getUid(), "additional:" + addDirName);
}
design.getOptions().put("sync", String.valueOf(oldConfig.getMode().equals("full")));
design.getOptions().put("autoupdate", String.valueOf(oldConfig.isAutoUpdate()));
design.getOptions().put("designkey", String.valueOf(oldConfig.getKey()));
cs.setDesign(design);
}
}
else if (oldConfig.getProvider().equals("db")) {
String dbDesignReference = oldConfig.getKey();
if (dbDesignReference != null) {
Design design = null;
if (dbDesignReference.startsWith(PluginConfig.PLUGIN_DBKEY_PREFIX)) {
String pluginInstallationKey = dbDesignReference.substring(PluginConfig.PLUGIN_DBKEY_PREFIX.length());
design = new Design(Constants.DESIGNCOL_PLUGIN, pluginInstallationKey);
}
else {
// find design provider db and migrate design config
// from there
ContentStore providerCS = (ContentStore) config.getContentDatabase(dbDesignReference);
if (providerCS == null) {
migrationResult.logError("Unable to migrate design of content store '" + cs.getKey() + "'. Design provider db '" + dbDesignReference + "' not found in wga.xml.");
}
// If the provider cs has no external design or it
// syncs,
// we must connect to it with db connection provider
else if (providerCS.getDesign() == null || "true".equals(providerCS.getDesign().getOptions().get("sync"))) {
design = new Design(Constants.DESIGNCOL_DB, dbDesignReference);
}
// Else we just connect to the same design with the same
// options
else {
design = new Design(providerCS.getDesign().getSource(), providerCS.getDesign().getName());
design.getOptions().putAll(providerCS.getDesign().getOptions());
}
}
if (design != null) {
if (design.getSource().equals(Constants.DESIGNCOL_DB)) {
design.getOptions().put("crossloginmode", oldConfig.getMode());
design.getOptions().put("variants", String.valueOf(oldConfig.isLookupDesignVariants()));
}
cs.setDesign(design);
}
}