Skip to content

Commit 065c045

Browse files
ottenhoffSakai Developer
andauthored
SAK-52117 Forums avoid stale id link issue (sakaiproject#14216)
Co-authored-by: Sakai Developer <[email protected]>
1 parent c41b5c0 commit 065c045

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

msgcntr/messageforums-app/src/java/org/sakaiproject/tool/messageforums/DiscussionForumTool.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,9 @@ public String processActionDisplayForum()
10161016
forumClickCount++;
10171017
if (getDecoratedForum() == null)
10181018
{
1019-
log.error("Forum not found");
1019+
log.warn("Forum not found for id {}", getExternalParameterByKey(FORUM_ID));
1020+
// Clear cached state so main view rebuilds after import/replace
1021+
reset();
10201022
return gotoMain();
10211023
}
10221024
return FORUM_DETAILS;
@@ -3798,6 +3800,12 @@ private Boolean resetTopicById(String externalTopicId)
37983800
{
37993801
Long.parseLong(topicId);
38003802
topic = forumManager.getTopicById(Long.valueOf(topicId));
3803+
if (topic == null) {
3804+
// Topic was not found, likely due to an import/replace or deletion.
3805+
log.warn("Topic with id '{}' not found", topicId);
3806+
setErrorMessage(getResourceBundleString(TOPIC_WITH_ID) + topicId + getResourceBundleString(NOT_FOUND_WITH_QUOTE));
3807+
return false;
3808+
}
38013809
}
38023810
catch (NumberFormatException e)
38033811
{
@@ -3841,9 +3849,11 @@ private String displayTopicById(String externalTopicId)
38413849
Event event = eventTrackingService.newEvent(DiscussionForumService.EVENT_FORUMS_TOPIC_READ, getEventReference(selectedTopic.getTopic()), null, true, NotificationService.NOTI_OPTIONAL, statement);
38423850
eventTrackingService.post(event);
38433851

3844-
return ALL_MESSAGES;
3852+
return ALL_MESSAGES;
38453853
} else {
3846-
return gotoMain();
3854+
// Clear cached state so main view rebuilds after import/replace
3855+
reset();
3856+
return gotoMain();
38473857
}
38483858
}
38493859

@@ -3853,6 +3863,8 @@ private void reset()
38533863
this.selectedForum = null;
38543864
this.selectedTopic = null;
38553865
this.selectedMessage = null;
3866+
this.selectedThreadHead = null;
3867+
this.selectedThread = new ArrayList();
38563868
// this.templateControlPermissions = null;
38573869
// this.templateMessagePermissions = null;
38583870
this.permissions=null;

msgcntr/messageforums-component-impl/src/java/org/sakaiproject/component/app/messageforums/MessageForumsForumManagerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,8 @@ public Topic getTopicById(final boolean open, final Long topicId) {
614614
HibernateCallback<Topic> hcb = session -> {
615615
Query q = session.getNamedQuery(QUERY_BY_TOPIC_ID);
616616
q.setParameter("id", topicId, LongType.INSTANCE);
617-
return (Topic) q.getSingleResult();
617+
// Use uniqueResult() so missing topics return null instead of throwing NoResultException.
618+
return (Topic) q.uniqueResult();
618619
};
619620

620621
Topic topic = (Topic) Hibernate.unproxy(getHibernateTemplate().execute(hcb));

0 commit comments

Comments
 (0)