diff --git a/app/jobs/submissions_job.rb b/app/jobs/submissions_job.rb index ff60f7e338..f0dadcd52e 100644 --- a/app/jobs/submissions_job.rb +++ b/app/jobs/submissions_job.rb @@ -18,24 +18,48 @@ def copy_old_grading_data(new_submission, grouping) .where(remark_request_submitted_at: nil) .last - collections = [ + result_data = [ { old: old_result.annotations, new: new_result.annotations }, { old: old_result.marks, new: new_result.marks }, { old: old_result.extra_marks, new: new_result.extra_marks } ] - collections.each do |collection| + # copy over data from old result + result_data.each do |result_set| # get rid of the existing empty records so we can replace them - collection[:new].all.destroy_all + result_set[:new].destroy_all - collection[:old].each do |item| + result_set[:old].each do |item| item_dup = item.dup - item_dup.result_id = new_result.id - item_dup.save + item_dup.update(result_id: new_result.id) add_warning_messages(item_dup.errors.full_messages) if item_dup.errors.present? end end + + # copy over old test data, which are on the submission instead of the result + old_submission.test_runs.each do |test_run| + test_run_dup = test_run.dup + test_run_dup.submission_id = new_submission.id + test_run_dup.save + + # don't continue if there are errors at this point + return add_warning_messages(test_run_dup.errors.full_messages) if test_run_dup.errors.present? + + test_run.test_group_results.each do |test_group_result| + test_group_result_dup = test_group_result.dup + test_group_result_dup.update(test_run_id: test_run_dup.id) + + return add_warning_messages(test_group_result_dup.errors.full_messages) if test_group_result_dup.errors.present? + + test_group_result.test_results.each do |test_result| + test_result_dup = test_result.dup + test_run_dup.update(test_group_result_id: test_group_result_dup.id) + + add_warning_messages(test_result_dup.errors.full_messages) if test_result_dup.errors.present? + end + end + end end def perform(groupings, apply_late_penalty: true, **options) @@ -59,7 +83,6 @@ def perform(groupings, apply_late_penalty: true, **options) new_submission = Submission.create_by_revision_identifier(grouping, options[:revision_identifier]) end - # here is where we would copy over old grading data if options[:retain_existing_grading] copy_old_grading_data(new_submission, grouping) end diff --git a/config/locales/views/submissions/en.yml b/config/locales/views/submissions/en.yml index 7d249f1612..835ec5129d 100644 --- a/config/locales/views/submissions/en.yml +++ b/config/locales/views/submissions/en.yml @@ -18,10 +18,10 @@ en: full_overwrite_warning: Collecting and grading this revision will overwrite any previous collections/grading done for this group on this assignment. Are you sure you want to do this? manual_collection: Manual Collection override_existing: Recollect previously collected submissions? - partial_overwrite_warning: Original marks and annotations will be retained upon collecting this revision, but all remark data and autotest results from previous collections/grading will still be lost for this group on this assignment. Are you sure you want to do this? + partial_overwrite_warning: Original marks, annotations, and test results will be retained upon collecting this revision, but all remark data from previous collections/grading will still be lost for this group on this assignment. Are you sure you want to do this? progress: "%{count}/%{size} submissions collected" results_loss_warning: This action identifies the version of files to grade for each selected group. Instructors and TAs can begin grading after files are collected. - retain_existing_grading: Retain existing grading data (marks and annotations) + retain_existing_grading: Retain existing grading data (marks, annotations, and test results) retain_existing_grading_warning_html: 'Retain existing grading data (Warning: without selecting this option, all old grading data for the collected submissions will be lost)' scanned_exam_latest_warning: For scanned exams, the latest submitted file version for each selected group is used regardless of the due date. status: