Skip to content
Snippets Groups Projects
Commit bd04b4a3 authored by Florian Gnaegi - frentix GmbH's avatar Florian Gnaegi - frentix GmbH
Browse files

OO-1065 properly update cp derlivery options to use defaults from repo

parent 0b17130f
No related branches found
No related tags found
No related merge requests found
......@@ -37,6 +37,8 @@ import org.olat.core.gui.control.generic.iframe.DeliveryOptions;
import org.olat.core.gui.control.generic.tabbable.TabbableController;
import org.olat.core.id.Identity;
import org.olat.core.id.OLATResourceable;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.core.util.Util;
import org.olat.core.util.resource.OresHelper;
import org.olat.course.ICourse;
......@@ -179,14 +181,19 @@ public class CPCourseNode extends AbstractAccessableCourseNode {
* previous behaviour
*/
public void updateModuleConfigDefaults(boolean isNewNode) {
int CURRENTVERSION = 7;
ModuleConfiguration config = getModuleConfiguration();
if (isNewNode) {
// use defaults for new course building blocks
config.setBooleanEntry(NodeEditController.CONFIG_STARTPAGE, Boolean.FALSE.booleanValue());
config.setBooleanEntry(NodeEditController.CONFIG_COMPONENT_MENU, Boolean.TRUE.booleanValue());
//fxdiff VCRP-13: cp navigation
// cp navigation
config.setBooleanEntry(CPEditController.CONFIG_SHOWNAVBUTTONS, Boolean.TRUE.booleanValue());
config.setConfigurationVersion(2);
// how to render files (include jquery etc)
DeliveryOptions nodeDeliveryOptions = DeliveryOptions.defaultWithGlossary();
nodeDeliveryOptions.setInherit(Boolean.TRUE);
config.set(CPEditController.CONFIG_DELIVERYOPTIONS, nodeDeliveryOptions);
config.setConfigurationVersion(CURRENTVERSION);
} else {
config.remove(NodeEditController.CONFIG_INTEGRATION);
if (config.getConfigurationVersion() < 2) {
......@@ -210,47 +217,65 @@ public class CPCourseNode extends AbstractAccessableCourseNode {
config.setBooleanEntry(CPEditController.CONFIG_SHOWNAVBUTTONS, Boolean.TRUE.booleanValue());
config.setConfigurationVersion(4);
}
if(config.getConfigurationVersion() < 5) {
// Version 5 was ineffective since the delivery options were not set. We have to redo this and
// save it as version 6
if(config.getConfigurationVersion() < 7) {
String contentEncoding = (String)config.get(NodeEditController.CONFIG_CONTENT_ENCODING);
if (contentEncoding != null && contentEncoding.equals("auto")) {
contentEncoding = null; // new style for auto
}
String jsEncoding = (String)config.get(NodeEditController.CONFIG_JS_ENCODING);
if (jsEncoding != null && jsEncoding.equals("auto")) {
jsEncoding = null; // new style for auto
}
CPPackageConfig reConfig = null;
DeliveryOptions nodeDeliveryOptions = new DeliveryOptions();
RepositoryEntry re = getReferencedRepositoryEntry();
if(re != null) {
reConfig = CPManager.getInstance().getCPPackageConfig(re.getOlatResource());
//move the settings from the node to the repo
if(reConfig == null || reConfig.getDeliveryOptions() == null) {
DeliveryOptions nodeDeliveryOptions = (DeliveryOptions)config.get(CPEditController.CONFIG_DELIVERYOPTIONS);
if (nodeDeliveryOptions == null) {
// Update missing delivery options now, inherit from repo by default
nodeDeliveryOptions = DeliveryOptions.defaultWithGlossary();
nodeDeliveryOptions.setInherit(Boolean.TRUE);
RepositoryEntry re = getReferencedRepositoryEntry();
// Check if delivery options are set for repo entry, if not create default
if(re != null) {
reConfig = CPManager.getInstance().getCPPackageConfig(re.getOlatResource());
if(reConfig == null) {
reConfig = new CPPackageConfig();
}
reConfig.setDeliveryOptions(new DeliveryOptions());
nodeDeliveryOptions.setInherit(Boolean.TRUE);
nodeDeliveryOptions.setStandardMode(Boolean.TRUE);
reConfig.getDeliveryOptions().setStandardMode(Boolean.TRUE);
reConfig.getDeliveryOptions().setContentEncoding(contentEncoding);
reConfig.getDeliveryOptions().setJavascriptEncoding(jsEncoding);
CPManager.getInstance().setCPPackageConfig(re.getOlatResource(), reConfig);
} else {
DeliveryOptions repoDeliveryOptions = reConfig.getDeliveryOptions();
if(((contentEncoding == null && repoDeliveryOptions.getContentEncoding() == null) || (contentEncoding != null && contentEncoding.equals(repoDeliveryOptions.getContentEncoding())))
&& ((jsEncoding == null && repoDeliveryOptions.getJavascriptEncoding() == null) || (jsEncoding != null && jsEncoding.equals(repoDeliveryOptions.getJavascriptEncoding())))) {
nodeDeliveryOptions.setInherit(Boolean.TRUE);
if (repoDeliveryOptions == null) {
// migrate existing config back to repo entry using the default as a base
repoDeliveryOptions = DeliveryOptions.defaultWithGlossary();
reConfig.setDeliveryOptions(repoDeliveryOptions);
repoDeliveryOptions.setContentEncoding(contentEncoding);
repoDeliveryOptions.setJavascriptEncoding(jsEncoding);
CPManager.getInstance().setCPPackageConfig(re.getOlatResource(), reConfig);
} else {
nodeDeliveryOptions.setInherit(Boolean.FALSE);
nodeDeliveryOptions.setContentEncoding(contentEncoding);
nodeDeliveryOptions.setJavascriptEncoding(jsEncoding);
// see if we have any different settings than the repo. if so, don't use inherit mode
if(contentEncoding != repoDeliveryOptions.getContentEncoding() || jsEncoding != repoDeliveryOptions.getJavascriptEncoding()) {
nodeDeliveryOptions.setInherit(Boolean.FALSE);
nodeDeliveryOptions.setContentEncoding(contentEncoding);
nodeDeliveryOptions.setJavascriptEncoding(jsEncoding);
}
}
}
// remove old config parameters
config.remove(NodeEditController.CONFIG_CONTENT_ENCODING);
config.remove(NodeEditController.CONFIG_JS_ENCODING);
// replace with new delivery options
config.set(CPEditController.CONFIG_DELIVERYOPTIONS, nodeDeliveryOptions);
}
config.setConfigurationVersion(5);
config.setConfigurationVersion(7);
}
// else node is up-to-date - nothing to do
}
if (config.getConfigurationVersion() != CURRENTVERSION) {
OLog logger = Tracing.createLoggerFor(CPCourseNode.class);
logger.error("CP course node version not updated to lastest version::" + CURRENTVERSION + ", was::" + config.getConfigurationVersion() + ". Check the code, programming error.");
}
}
/**
......
......@@ -162,7 +162,7 @@ public class CPRunController extends BasicController implements ControllerEventL
}
@Override
//fxdiff BAKS-7 Resume function
// Resume function
public void activate(UserRequest ureq, List<ContextEntry> entries, StateEntry state) {
if(entries == null || entries.isEmpty()) return;
......@@ -205,8 +205,8 @@ public class CPRunController extends BasicController implements ControllerEventL
//fxdiff VCRP-13: cp navigation
boolean navButtons = isNavButtonConfigured();
cpDispC = CPUIFactory.getInstance().createContentOnlyCPDisplayController(ureq, getWindowControl(), new LocalFolderImpl(cpRoot), activateFirstPage, navButtons, deliveryOptions, nodecmd, courseResource);
cpDispC.setContentEncoding(getContentEncoding());
cpDispC.setJSEncoding(getJSEncoding());
cpDispC.setContentEncoding(deliveryOptions.getContentEncoding());
cpDispC.setJSEncoding(deliveryOptions.getJavascriptEncoding());
cpDispC.addControllerListener(this);
main.setContent(cpDispC.getInitialComponent());
......@@ -232,29 +232,15 @@ public class CPRunController extends BasicController implements ControllerEventL
private boolean isExternalMenuConfigured() {
return (config.getBooleanEntry(NodeEditController.CONFIG_COMPONENT_MENU).booleanValue());
}
//fxdiff VCRP-13: cp navigation
/**
* @return true: show next-previous buttons; false: hide next-previous buttons
*/
private boolean isNavButtonConfigured() {
Boolean navButton = config.getBooleanEntry(CPEditController.CONFIG_SHOWNAVBUTTONS);
return navButton == null ? true : navButton.booleanValue();
}
private String getContentEncoding() {
String encoding = (String)config.get(NodeEditController.CONFIG_CONTENT_ENCODING);
if(!encoding.equals(NodeEditController.CONFIG_CONTENT_ENCODING_AUTO)) {
return encoding;
}
return null;
}
private String getJSEncoding() {
String encoding = (String)config.get(NodeEditController.CONFIG_JS_ENCODING);
if(!encoding.equals(NodeEditController.CONFIG_JS_ENCODING_AUTO)) {
return encoding;
}
return null;
}
/**
* @see org.olat.core.gui.control.DefaultController#doDispose(boolean)
*/
......
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