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