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