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

OO-975: fix wrong business path if the user start the editor and return to the...

OO-975: fix wrong business path if the user start the editor and return to the course, upgrade publishers with partial business path
parent d429d7ef
No related branches found
No related tags found
No related merge requests found
......@@ -888,20 +888,22 @@ public class RepositoryDetailsController extends BasicController implements Gene
}
OLATResourceable ores = re.getOlatResource();
BusinessControlFactory bcFactory = BusinessControlFactory.getInstance();
//was brasato:: DTabs dts = getWindowControl().getDTabs();
DTabs dts = Windows.getWindows(ureq).getWindow(ureq).getDTabs();
DTab dt = dts.getDTab(ores);
if (dt == null) {
// does not yet exist -> create and add
//fxdiff BAKS-7 Resume function
dt = dts.createDTab(ores, re, re.getDisplayname());
if (dt == null){
//null means DTabs are full -> warning is shown
return;
}
//user activity logger is set by course factory
Controller editorController = typeToEdit.createEditorController(re, ureq, dt.getWindowControl());
ContextEntry entry = bcFactory.createContextEntry(re);
WindowControl swControl = bcFactory.createBusinessWindowControl(entry, dt.getWindowControl());
Controller editorController = typeToEdit.createEditorController(re, ureq, swControl);
if(editorController == null){
//editor could not be created -> warning is shown
return;
......@@ -909,7 +911,7 @@ public class RepositoryDetailsController extends BasicController implements Gene
dt.setController(editorController);
dts.addDTab(ureq, dt);
}
List<ContextEntry> entries = BusinessControlFactory.getInstance().createCEListFromResourceType(RepositoryDetailsController.ACTIVATE_EDITOR);
List<ContextEntry> entries = bcFactory.createCEListFromResourceType(RepositoryDetailsController.ACTIVATE_EDITOR);
dts.activate(ureq, dt, entries);
}
......
......@@ -22,11 +22,16 @@ package org.olat.upgrade;
import java.util.List;
import org.olat.core.commons.persistence.DB;
import org.olat.core.commons.services.notifications.Publisher;
import org.olat.core.id.OLATResourceable;
import org.olat.core.util.mail.MailManager;
import org.olat.core.util.resource.OresHelper;
import org.olat.group.BusinessGroup;
import org.olat.group.BusinessGroupImpl;
import org.olat.properties.Property;
import org.olat.properties.PropertyManager;
import org.olat.repository.RepositoryEntry;
import org.olat.repository.RepositoryManager;
import org.springframework.beans.factory.annotation.Autowired;
/**
......@@ -39,6 +44,7 @@ public class OLATUpgrade_9_4_0 extends OLATUpgrade {
private static final int BATCH_SIZE = 50;
private static final String TASK_DISPLAY_MEMBERS = "Upgrade display members";
private static final String FIX_PUBLISHER_BUSINESSPATH = "Fix publishers business path";
private static final String VERSION = "OLAT_9.4.0";
private static final String PROP_NAME = "displayMembers";
......@@ -50,6 +56,8 @@ public class OLATUpgrade_9_4_0 extends OLATUpgrade {
private MailManager mailManager;
@Autowired
private PropertyManager propertyManager;
@Autowired
private RepositoryManager repositoryManager;
public OLATUpgrade_9_4_0() {
super();
......@@ -76,6 +84,7 @@ public class OLATUpgrade_9_4_0 extends OLATUpgrade {
}
boolean allOk = upgradeDisplayMembers(upgradeManager, uhd);
allOk &= fixBusinessPathPublisher(upgradeManager, uhd);
uhd.setInstallationComplete(allOk);
upgradeManager.setUpgradesHistory(uhd, VERSION);
......@@ -87,6 +96,59 @@ public class OLATUpgrade_9_4_0 extends OLATUpgrade {
return allOk;
}
private boolean fixBusinessPathPublisher(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
if (!uhd.getBooleanDataValue(FIX_PUBLISHER_BUSINESSPATH)) {
List<Publisher> publishers = getPublishers();
int count = 0;
int updates = 0;
for(Publisher publisher:publishers) {
boolean updated = processPublisher(publisher);
if(count % 10 == 0) {
dbInstance.commit();
}
if(updated) updates++;
}
dbInstance.commit();
log.audit("Update " + updates + " publisher with partial business path.");
uhd.setBooleanDataValue(FIX_PUBLISHER_BUSINESSPATH, true);
upgradeManager.setUpgradesHistory(uhd, VERSION);
}
return true;
}
private boolean processPublisher(Publisher publisher) {
OLATResourceable ores = OresHelper.createOLATResourceableInstance(publisher.getResName(), publisher.getResId());
RepositoryEntry re = repositoryManager.lookupRepositoryEntry(ores, false);
if(re != null) {
String businessPath = publisher.getBusinessPath();
String newPath = "[RepositoryEntry:" + re.getKey() + "]" + businessPath;
publisher.setBusinessPath(newPath);
StringBuilder sb = new StringBuilder();
sb.append("update notipublisher pub set pub.businessPath=:newPath ")
.append("where pub.key=:pubKey");
int rows = dbInstance.getCurrentEntityManager().createQuery(sb.toString())
.setParameter("newPath", newPath)
.setParameter("pubKey", publisher.getKey())
.executeUpdate();
if(rows != 1) {
log.error("Cannot update publisher with key: " + publisher.getKey());
}
return rows == 1;
} else {
log.error("Cannot update publisher with key: " + publisher.getKey() + " don't find an according repository entry");
return false;
}
}
private List<Publisher> getPublishers() {
String q = "select pub from notipublisher pub where pub.businessPath like '[CourseNode:%'";
return dbInstance.getCurrentEntityManager().createQuery(q, Publisher.class)
.getResultList();
}
private static final int showOwnersVal = 1;// 0x..0001
private static final int showPartipsVal = 2;// 0x..0010
private static final int showWaitingListVal = 4;// 0x..0100
......@@ -154,7 +216,7 @@ public class OLATUpgrade_9_4_0 extends OLATUpgrade {
log.audit("Business groups processed: " + groups.size());
dbInstance.commitAndCloseSession();
} while(groups.size() == BATCH_SIZE);
uhd.setBooleanDataValue(TASK_DISPLAY_MEMBERS, false);
uhd.setBooleanDataValue(TASK_DISPLAY_MEMBERS, true);
upgradeManager.setUpgradesHistory(uhd, VERSION);
}
return true;
......
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