rake任务调整

ecloud_sso
cxt 5 years ago
parent d48f70dee0
commit 75d009c974

@ -193,6 +193,16 @@ namespace :migrate_course_resource do
target_course = Course.find_by(id: target_id)
return if source_course.blank? || target_course.blank?
# 先把target——course中的老师创建分班权限
target_course.teachers.each do |member|
if member.teacher_course_groups.blank?
target_course.course_groups.each do |group|
TeacherCourseGroup.create!(course_group_id: group.id, course_id: target_course.id, course_member_id: member&.id, user_id: member&.user_id)
end
end
end
source_course.course_members.where(role: %i[PROFESSOR ASSISTANT_PROFESSOR]).each do |teacher|
new_member = target_course.teachers.find_by(user_id: teacher.user_id)
unless new_member.present?
@ -210,7 +220,7 @@ namespace :migrate_course_resource do
group.course_members.where(role: 4).each do |member|
new_member = target_course.students.find_by(user_id: member.user_id)
if new_member.present?
new_member.update_column("course_group_id", new_group.id)
new_member.update_attributes(course_group_id: new_group.id)
else
CourseMember.create!(course_id: target_course.id, course_group_id: new_group.id, user_id: member.user_id, role: member.role)
new_user_ids << member.user_id
@ -221,7 +231,7 @@ namespace :migrate_course_resource do
group.teacher_course_groups.each do |teacher_group|
member = CourseMember.find_by(course_id: target_course.id, user_id: teacher_group.user_id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR])
if member.present?
if member.present? && member.teacher_course_groups.where(course_group_id: new_group.id).exists?
TeacherCourseGroup.create!(course_group_id: new_group.id, course_id: target_course.id, course_member_id: member&.id, user_id: member&.user_id)
end
end
@ -231,7 +241,7 @@ namespace :migrate_course_resource do
source_course.students.where(course_group_id: 0).each do |member|
new_member = target_course.students.find_by(user_id: member.user_id)
if new_member.present?
new_member.update_column("course_group_id", 0)
new_member.update_attributes(course_group_id: 0)
else
CourseMember.create!(course_id: target_course.id, course_group_id: 0, user_id: member.user_id, role: member.role)
user_ids << member.user_id

Loading…
Cancel
Save