create roll back data for section importer
closes CORE-1391 test plan - import sections - workflow_state changes should be logged Change-Id: I18d24bd0dbffb26c9132a63e5b9da937e0742455 Reviewed-on: https://gerrit.instructure.com/150100 Reviewed-by: James Williams <jamesw@instructure.com> Tested-by: Jenkins QA-Review: Rohan Cheeniyil <rcheeniyil@instructure.com> Product-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
parent
3aa5acc6ca
commit
063e36faa4
|
@ -20,7 +20,7 @@ module SIS
|
|||
class SectionImporter < BaseImporter
|
||||
|
||||
def process
|
||||
start = Time.now
|
||||
start = Time.zone.now
|
||||
importer = Work.new(@batch, @root_account, @logger)
|
||||
CourseSection.suspend_callbacks(:delete_enrollments_later_if_deleted) do
|
||||
Course.skip_updating_account_associations do
|
||||
|
@ -38,18 +38,16 @@ module SIS
|
|||
# it can run really fast
|
||||
Shackles.activate(:slave) do
|
||||
# ideally we change this to find_in_batches, and call (the currently non-existent) Enrollment.destroy_batch
|
||||
Enrollment.where(course_section_id: importer.deleted_section_ids.to_a).active.find_each do |enrollment|
|
||||
Enrollment.where(course_section_id: importer.deleted_section_ids.to_a).active.find_in_batches do |enrollments|
|
||||
Shackles.activate(:master) do
|
||||
begin
|
||||
enrollment.destroy
|
||||
rescue => e
|
||||
::Canvas::Errors.capture(e, type: :sis_import, account: @batch.account)
|
||||
raise ImportError, "Failed to remove enrollment #{enrollment.id} from section #{enrollment.course_section.sis_source_id}"
|
||||
end
|
||||
new_data = Enrollment::BatchStateUpdater.destroy_batch(enrollments, sis_batch: @batch)
|
||||
importer.roll_back_data.push(*new_data)
|
||||
SisBatchRollBackData.bulk_insert_roll_back_data(importer.roll_back_data) if @batch.using_parallel_importers?
|
||||
importer.roll_back_data = []
|
||||
end
|
||||
end
|
||||
end
|
||||
@logger.debug("Sections took #{Time.now - start} seconds")
|
||||
@logger.debug("Sections took #{Time.zone.now - start} seconds")
|
||||
return importer.success_count
|
||||
end
|
||||
|
||||
|
@ -58,7 +56,8 @@ module SIS
|
|||
:success_count,
|
||||
:sections_to_update_sis_batch_ids,
|
||||
:course_ids_to_update_associations,
|
||||
:deleted_section_ids
|
||||
:deleted_section_ids,
|
||||
:roll_back_data
|
||||
)
|
||||
|
||||
def initialize(batch, root_account, logger)
|
||||
|
@ -67,6 +66,7 @@ module SIS
|
|||
@logger = logger
|
||||
@success_count = 0
|
||||
@sections_to_update_sis_batch_ids = []
|
||||
@roll_back_data = []
|
||||
@course_ids_to_update_associations = Set.new
|
||||
@deleted_section_ids = Set.new
|
||||
end
|
||||
|
@ -131,6 +131,8 @@ module SIS
|
|||
section.sis_batch_id = @batch.id if @batch
|
||||
if section.valid?
|
||||
section.save
|
||||
data = SisBatchRollBackData.build_data(sis_batch: @batch, context: section)
|
||||
@roll_back_data << data if data
|
||||
else
|
||||
msg = "A section did not pass validation "
|
||||
msg += "(" + "section: #{section_id} / #{name}, course: #{course_id}, error: "
|
||||
|
|
|
@ -75,6 +75,37 @@ describe SIS::CSV::SectionImporter do
|
|||
expect(importer.errors).to eq []
|
||||
end
|
||||
|
||||
it 'should create rollback data' do
|
||||
@account.enable_feature!(:refactor_of_sis_imports)
|
||||
batch1 = @account.sis_batches.create! { |sb| sb.data = {} }
|
||||
process_csv_data_cleanly(
|
||||
"course_id,short_name,long_name,account_id,term_id,status",
|
||||
"C001,TC 101,Test Course 101,,,active"
|
||||
)
|
||||
process_csv_data_cleanly(
|
||||
"section_id,course_id,name,start_date,end_date,status",
|
||||
"1B,C001,Sec1,2011-1-05 00:00:00,2011-4-14 00:00:00,active"
|
||||
)
|
||||
process_csv_data_cleanly(
|
||||
"user_id,login_id,first_name,last_name,email,status",
|
||||
"U001,user1,User,Uno,user@example.com,active"
|
||||
)
|
||||
process_csv_data_cleanly(
|
||||
"course_id,user_id,role,section_id,status",
|
||||
"C001,U001,student,1B,active"
|
||||
)
|
||||
|
||||
g = Course.where(sis_source_id: 'C001').take.groups.create!(name: 'group')
|
||||
g.group_memberships.create!(user: Pseudonym.where(sis_user_id: 'U001').take.user)
|
||||
process_csv_data_cleanly(
|
||||
"section_id,course_id,name,start_date,end_date,status",
|
||||
"1B,C001,Sec1,2011-1-05 00:00:00,2011-4-14 00:00:00,deleted",
|
||||
batch: batch1
|
||||
)
|
||||
# 1. section, 2. enrollment, 3. group_membership
|
||||
expect(batch1.roll_back_data.count).to eq 3
|
||||
end
|
||||
|
||||
it 'should ignore unsupported column account_id' do
|
||||
process_csv_data_cleanly(
|
||||
"course_id,short_name,long_name,account_id,term_id,status",
|
||||
|
|
Loading…
Reference in New Issue