Skip to content

Commit

Permalink
SAK-42098 : Merging/Replacing data in Site Info loses custom tool nam…
Browse files Browse the repository at this point in the history
…e changes (sakaiproject#7107)
  • Loading branch information
frasese authored and bjones86 committed Jul 23, 2019
1 parent 5f27a6e commit 2b0f9a3
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,39 @@ public String transferSiteResource(String oSiteId, String nSiteId, String siteAt

return rv;
}

/**
* Helper to copy the tool title from one site to another.
* <p>
* Note that it does NOT save the site. The caller must handle this.
*
* @param toSite the site to update
* @param fromSiteId the site id to copy from
* @param importTools the tool id to copy
* @return site the updated site object
*/
private Site setToolTitle(Site toSite, String fromSiteId, String toolId) {
try {
if (toSite.getToolForCommonId(toolId) != null) {
Site fromSite = siteService.getSite(fromSiteId);
for (ToolConfiguration tc : fromSite.getTools(toolId)) {
try {
ToolConfiguration toTc = toSite.getToolForCommonId(toolId);
toTc.getContainingPage().setTitle(tc.getContainingPage().getTitle());
toTc.getContainingPage().setTitleCustom(tc.getContainingPage().getTitleCustom());
toTc.setTitle(tc.getTitle());
} catch (Exception e) {
log.warn("Can't set tool title, {}", e.getMessage());
}
}
} else {
log.debug("Site : {} does not have the tool: {}", toSite.getTitle(), toolId);
}
} catch (Exception e) {
log.warn("Error setting tool title from {} to {} : {}", fromSiteId, toSite.getId(), e.getMessage());
}
return toSite;
}

/**
* Helper to add a tool to a site if the site does not contain an instance of the tool.
Expand Down Expand Up @@ -345,6 +378,20 @@ public void importToolsIntoSite(Site site, List<String> toolIds, Map<String, Lis
toolIds.clear();
toolIds.addAll(importTools.keySet());
}

//set custom title
if (cleanup) {
log.debug("allToolIds: " + toolIds);
for (String toolId : toolIds) {
try {
String siteFromId = importTools.get(toolId).get(0);
site = setToolTitle(site, siteFromId, toolId);
saveSite(site);
} catch (Exception e) {
log.warn("Problem with {}: {}", toolId, e.getMessage());
}
}
}

Map<String, String> transversalMap = new HashMap<>();

Expand Down

0 comments on commit 2b0f9a3

Please sign in to comment.