From 6177431cd35b29e9f20505dd70e490d704bb8bc7 Mon Sep 17 00:00:00 2001
From: srosse <stephane.rosse@frentix.com>
Date: Wed, 1 Apr 2020 14:47:20 +0200
Subject: [PATCH] OO-4613: check if reminders are sent before sending them
 again

---
 .../olat/modules/grading/manager/GradingServiceImpl.java  | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/olat/modules/grading/manager/GradingServiceImpl.java b/src/main/java/org/olat/modules/grading/manager/GradingServiceImpl.java
index 0bf617815ca..b43e5bfdd48 100644
--- a/src/main/java/org/olat/modules/grading/manager/GradingServiceImpl.java
+++ b/src/main/java/org/olat/modules/grading/manager/GradingServiceImpl.java
@@ -573,11 +573,11 @@ public class GradingServiceImpl implements GradingService, UserDataDeletable, Re
 		for(GradingAssignment assignment:inexactList) {
 			try {
 				RepositoryEntryGradingConfiguration config = gradingConfigurationDao.getConfiguration(assignment.getReferenceEntry());
-				if(exactReminderCalculation(assignment, config.getFirstReminder())) {
+				if(exactReminderCalculation(assignment, assignment.getReminder1Date(), config.getFirstReminder())) {
 					reminder(assignment, config.getFirstReminderSubject(), config.getFirstReminderBody());
 					assignment.setReminder1Date(new Date());
 					gradingAssignmentDao.updateAssignment(assignment);
-				} else if(exactReminderCalculation(assignment, config.getSecondReminder())) {
+				} else if(exactReminderCalculation(assignment, assignment.getReminder2Date(), config.getSecondReminder())) {
 					reminder(assignment, config.getSecondReminderSubject(), config.getSecondReminderBody());
 					assignment.setReminder2Date(new Date());
 					gradingAssignmentDao.updateAssignment(assignment);
@@ -590,8 +590,8 @@ public class GradingServiceImpl implements GradingService, UserDataDeletable, Re
 		}
 	}
 	
-	private boolean exactReminderCalculation(GradingAssignment assignment, Integer reminderPeriod) {
-		if(reminderPeriod == null) return false;
+	private boolean exactReminderCalculation(GradingAssignment assignment, Date sendReminderDate, Integer reminderPeriod) {
+		if(reminderPeriod == null || sendReminderDate != null) return false;
 		
 		Date assignmentDate = assignment.getAssignmentDate();
 		Date assignmentDatePlusPeriod = CalendarUtils.addWorkingDays(assignmentDate, reminderPeriod.intValue());
-- 
GitLab