From e600ffb6b9039f1e9e93a1cc9f1e34758ab7fc33 Mon Sep 17 00:00:00 2001 From: jorg-vr Date: Fri, 10 Nov 2023 14:02:04 +0100 Subject: [PATCH] Never remove exercises that are part of an evaluation --- app/jobs/remove_activities_job.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/jobs/remove_activities_job.rb b/app/jobs/remove_activities_job.rb index 14f7a8c612..7026602af7 100644 --- a/app/jobs/remove_activities_job.rb +++ b/app/jobs/remove_activities_job.rb @@ -2,6 +2,7 @@ class RemoveActivitiesJob < ApplicationJob # permanently remove activities that match all of the following criteria: # - status is 'removed' # - updated_at is more than 1 month ago + # - not part of an evaluation # - one of the following is true: # - draft is true (never published) # - series_memberships is empty and less then 25 submissions and latest submission is more than 1 month ago @@ -28,6 +29,8 @@ def perform next if activity.submissions.present? && activity.submissions.reorder(:created_at).last.created_at > 1.month.ago end + next if EvaluationExercise.exists?(exercise_id: activity.id) + # destroy submissions first explicitly, as they are dependent: :restrict_with_error activity.submissions.destroy_all