File tree Expand file tree Collapse file tree 2 files changed +14
-9
lines changed Expand file tree Collapse file tree 2 files changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -92,11 +92,7 @@ def active_admin_import(options = {}, &block)
9292 else
9393 instance_exec result , options , &DEFAULT_RESULT_PROC
9494 end
95- rescue ActiveRecord ::Import ::MissingColumnError ,
96- NoMethodError ,
97- ActiveRecord ::StatementInvalid ,
98- CSV ::MalformedCSVError ,
99- ActiveAdminImport ::Exception => e
95+ rescue StandardError => e
10096 Rails . logger . error ( I18n . t ( 'active_admin_import.file_error' , message : e . message ) )
10197 Rails . logger . error ( e . backtrace . join ( "\n " ) )
10298 flash [ :error ] = I18n . t ( 'active_admin_import.file_error' , message : e . message [ 0 ..200 ] )
Original file line number Diff line number Diff line change @@ -139,12 +139,21 @@ def run_callback(name)
139139 end
140140
141141 def batch_import
142+ @resource . respond_to? ( :transaction ) ? batch_improt_with_transaction : batch_import_without_transaction
143+ end
144+
145+ def batch_import_without_transaction
146+ run_callback ( :before_batch_import )
147+ batch_result = resource . import ( headers . values , csv_lines , import_options )
148+ raise ActiveRecord ::Rollback if Object . const_defined? ( 'ActiveRecord::Rollback' ) && import_options [ :batch_transaction ] && batch_result . failed_instances . any?
149+ run_callback ( :after_batch_import )
150+ batch_result
151+ end
152+
153+ def batch_improt_with_transaction
142154 batch_result = nil
143155 @resource . transaction do
144- run_callback ( :before_batch_import )
145- batch_result = resource . import ( headers . values , csv_lines , import_options )
146- raise ActiveRecord ::Rollback if import_options [ :batch_transaction ] && batch_result . failed_instances . any?
147- run_callback ( :after_batch_import )
156+ batch_result = batch_import_without_transaction
148157 end
149158 batch_result
150159 end
You can’t perform that action at this time.
0 commit comments