File tree 2 files changed +14
-9
lines changed
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)
92
92
else
93
93
instance_exec result , options , &DEFAULT_RESULT_PROC
94
94
end
95
- rescue ActiveRecord ::Import ::MissingColumnError ,
96
- NoMethodError ,
97
- ActiveRecord ::StatementInvalid ,
98
- CSV ::MalformedCSVError ,
99
- ActiveAdminImport ::Exception => e
95
+ rescue StandardError => e
100
96
Rails . logger . error ( I18n . t ( 'active_admin_import.file_error' , message : e . message ) )
101
97
Rails . logger . error ( e . backtrace . join ( "\n " ) )
102
98
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)
139
139
end
140
140
141
141
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
142
154
batch_result = nil
143
155
@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
148
157
end
149
158
batch_result
150
159
end
You can’t perform that action at this time.
0 commit comments