Skip to content

Commit 004ef90

Browse files
authored
Merge pull request doubtfire-lms#472 from b0ink/feat/merge-imported-students
Feat/merge imported students
2 parents 7f485a4 + fcbe843 commit 004ef90

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

app/models/unit.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ def sync_enrolment_with(enrolment_data, import_settings, result)
753753
enrolment_data.each do |row_data|
754754
begin
755755
if row_data[:username].nil?
756-
ignored << { row: row, message: "Skipping row with missing username" }
756+
ignored << { row: row_data[:row], message: "Skipping row with missing username" }
757757
next
758758
end
759759

@@ -775,11 +775,25 @@ def sync_enrolment_with(enrolment_data, import_settings, result)
775775
ignored_entry = { row: changes[username][:row], message: 'Skipping duplicate role - ensuring enrolled.' }
776776

777777
# Allocate+ csv data may have duplicate student rows for each tutorial enrolment
778-
# We need to combine the tutorials from both rows so that the student is enrolled into each tutorial
779-
if import_settings[:merge_tutorials_for_duplicate_students] && changes[username][:tutorials]&.any?
778+
if import_settings[:merge_duplicate_students]
779+
# Init the tutorials array if nil
780780
row_data[:tutorials] ||= []
781+
changes[username][:tutorials] ||= []
782+
783+
# Combine the tutorials from both rows so that the student is enrolled into each tutorial
781784
row_data[:tutorials].concat(changes[username][:tutorials])
782-
ignored_entry[:message] += ' Merged tutorial enrolments.'
785+
786+
# Prefer values from previous row, but fallback to current row data if nil
787+
row_data[:unit_code] = changes[username][:unit_code] || row_data[:unit_code]
788+
row_data[:username] = changes[username][:username] || row_data[:username]
789+
row_data[:student] = changes[username][:student] || row_data[:student]
790+
row_data[:first] = changes[username][:first] || row_data[:first]
791+
row_data[:last] = changes[username][:last] || row_data[:last]
792+
row_data[:nickname] = changes[username][:nickname] || row_data[:nickname]
793+
row_data[:email] = changes[username][:email] || row_data[:email]
794+
row_data[:enrolled] = changes[username][:enrolled] || row_data[:enrolled]
795+
row_data[:campus] = changes[username][:campus] || row_data[:campus]
796+
ignored_entry[:message] += ' Merged duplicate student data.'
783797
end
784798

785799
ignored << ignored_entry

0 commit comments

Comments
 (0)