Skip to content
Snippets Groups Projects
Commit f5de0bc8 authored by srosse's avatar srosse
Browse files

OO-1825: hardened the upgrader against old preferences mapping

parent 3e3322d5
No related branches found
No related tags found
No related merge requests found
...@@ -34,7 +34,6 @@ import org.olat.commons.calendar.model.ImportedCalendar; ...@@ -34,7 +34,6 @@ import org.olat.commons.calendar.model.ImportedCalendar;
import org.olat.commons.calendar.model.ImportedToCalendar; import org.olat.commons.calendar.model.ImportedToCalendar;
import org.olat.commons.calendar.model.Kalendar; import org.olat.commons.calendar.model.Kalendar;
import org.olat.core.commons.persistence.DB; import org.olat.core.commons.persistence.DB;
import org.olat.core.commons.persistence.DBFactory;
import org.olat.core.id.Identity; import org.olat.core.id.Identity;
import org.olat.core.util.StringHelper; import org.olat.core.util.StringHelper;
import org.olat.core.util.xml.XStreamHelper; import org.olat.core.util.xml.XStreamHelper;
...@@ -62,6 +61,8 @@ public class OLATUpgrade_10_4_0 extends OLATUpgrade { ...@@ -62,6 +61,8 @@ public class OLATUpgrade_10_4_0 extends OLATUpgrade {
private static final XStream xstream = XStreamHelper.createXStreamInstance(); private static final XStream xstream = XStreamHelper.createXStreamInstance();
static { static {
xstream.ignoreUnknownElements();
xstream.alias("org.olat.preferences.DbPrefs", UpgradePreferences.class);
xstream.alias("org.olat.core.util.prefs.db.DbPrefs", UpgradePreferences.class); xstream.alias("org.olat.core.util.prefs.db.DbPrefs", UpgradePreferences.class);
xstream.alias("org.olat.commons.calendar.model.KalendarConfig", KalendarConfig.class); xstream.alias("org.olat.commons.calendar.model.KalendarConfig", KalendarConfig.class);
} }
...@@ -79,8 +80,6 @@ public class OLATUpgrade_10_4_0 extends OLATUpgrade { ...@@ -79,8 +80,6 @@ public class OLATUpgrade_10_4_0 extends OLATUpgrade {
@Autowired @Autowired
private CalendarUserConfigurationDAO calendarUserConfigurationDao; private CalendarUserConfigurationDAO calendarUserConfigurationDao;
public OLATUpgrade_10_4_0() { public OLATUpgrade_10_4_0() {
super(); super();
} }
...@@ -171,7 +170,7 @@ public class OLATUpgrade_10_4_0 extends OLATUpgrade { ...@@ -171,7 +170,7 @@ public class OLATUpgrade_10_4_0 extends OLATUpgrade {
.append(" where v.category='icalAuthToken' and v.name='authToken'") .append(" where v.category='icalAuthToken' and v.name='authToken'")
.append(" order by v.key"); .append(" order by v.key");
return DBFactory.getInstance().getCurrentEntityManager() return dbInstance.getCurrentEntityManager()
.createQuery(sb.toString(), Property.class) .createQuery(sb.toString(), Property.class)
.setFirstResult(firstResult) .setFirstResult(firstResult)
.setMaxResults(maxResult) .setMaxResults(maxResult)
...@@ -208,26 +207,31 @@ public class OLATUpgrade_10_4_0 extends OLATUpgrade { ...@@ -208,26 +207,31 @@ public class OLATUpgrade_10_4_0 extends OLATUpgrade {
.append(" where v.name='v2guipreferences'") .append(" where v.name='v2guipreferences'")
.append(" order by v.key"); .append(" order by v.key");
return DBFactory.getInstance().getCurrentEntityManager() return dbInstance.getCurrentEntityManager()
.createQuery(sb.toString(), Property.class) .createQuery(sb.toString(), Property.class)
.setFirstResult(firstResult) .setFirstResult(firstResult)
.setMaxResults(maxResult) .setMaxResults(maxResult)
.getResultList(); .getResultList();
} }
private void processCalendarGUIProperty(Property property) { private void processCalendarGUIProperty(Property property) {
String text = property.getTextValue(); String text = property.getTextValue();
if(StringHelper.containsNonWhitespace(text)) { if(StringHelper.containsNonWhitespace(text)) {
UpgradePreferences prefs = (UpgradePreferences)xstream.fromXML(text); try {
Map<String,Object> preferenceMap = prefs.getPreferences(); UpgradePreferences prefs = (UpgradePreferences)xstream.fromXML(text);
for(Map.Entry<String,Object> entry:preferenceMap.entrySet()) { if(prefs != null) {
String key = entry.getKey(); Map<String,Object> preferenceMap = prefs.getPreferences();
if(key.startsWith(KALENDAR_GUI_MARKER)) { for(Map.Entry<String,Object> entry:preferenceMap.entrySet()) {
String calendarId = key.substring(KALENDAR_GUI_MARKER.length(), key.length()); String key = entry.getKey();
KalendarConfig config = (KalendarConfig)entry.getValue(); if(key.startsWith(KALENDAR_GUI_MARKER)) {
processKalendarConfig(property.getIdentity(), calendarId, config); String calendarId = key.substring(KALENDAR_GUI_MARKER.length(), key.length());
KalendarConfig config = (KalendarConfig)entry.getValue();
processKalendarConfig(property.getIdentity(), calendarId, config);
}
}
} }
} catch (Exception e) {
log.warn("Cannot read the preferences", e);
} }
} }
} }
...@@ -310,7 +314,7 @@ public class OLATUpgrade_10_4_0 extends OLATUpgrade { ...@@ -310,7 +314,7 @@ public class OLATUpgrade_10_4_0 extends OLATUpgrade {
.append(" where v.category='Imported-Calendar'") .append(" where v.category='Imported-Calendar'")
.append(" order by v.key"); .append(" order by v.key");
return DBFactory.getInstance().getCurrentEntityManager() return dbInstance.getCurrentEntityManager()
.createQuery(sb.toString(), Property.class) .createQuery(sb.toString(), Property.class)
.setFirstResult(firstResult) .setFirstResult(firstResult)
.setMaxResults(maxResult) .setMaxResults(maxResult)
...@@ -374,7 +378,7 @@ public class OLATUpgrade_10_4_0 extends OLATUpgrade { ...@@ -374,7 +378,7 @@ public class OLATUpgrade_10_4_0 extends OLATUpgrade {
.append(" where v.category='Imported-Calendar-To'") .append(" where v.category='Imported-Calendar-To'")
.append(" order by v.key"); .append(" order by v.key");
return DBFactory.getInstance().getCurrentEntityManager() return dbInstance.getCurrentEntityManager()
.createQuery(sb.toString(), Property.class) .createQuery(sb.toString(), Property.class)
.setFirstResult(firstResult) .setFirstResult(firstResult)
.setMaxResults(maxResult) .setMaxResults(maxResult)
......
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