@@ -202,16 +202,19 @@ def self.import_training_documents
202202 importable_rows = match_csv_with_azure_files ( valid_csv_rows , azure_files )
203203 unmatched_files = collect_unmatched_files ( csv_data , azure_files , importable_rows )
204204
205- log_import_summary ( valid_csv_rows , azure_files , importable_rows )
205+ report . update! (
206+ summary_stats : build_summary_stats ( import_stats , csv_data , azure_files ) ,
207+ unmatched_files : unmatched_files ,
208+ status : "planned"
209+ )
206210
207- process_document_attachments ( importable_rows , import_stats )
211+ process_document_attachments ( importable_rows , import_stats , report )
208212
209213 report . update! (
210214 completed_at : Time . current ,
211215 status : "completed" ,
212216 summary_stats : build_summary_stats ( import_stats , csv_data , azure_files ) ,
213- unmatched_files : unmatched_files ,
214- error_details : import_stats [ :error_files ]
217+ unmatched_files : unmatched_files
215218 )
216219
217220 log_final_results ( import_stats )
@@ -254,16 +257,16 @@ def self.match_csv_with_azure_files(csv_rows, azure_files)
254257 end
255258 end
256259
257- def self . process_document_attachments ( rows , stats )
260+ def self . process_document_attachments ( rows , stats , report )
258261 rows . each do |row |
259262 topic = Topic . find_by ( id : row [ "Topic_ID" ] )
260263 next unless topic
261264
262- attach_document_to_topic ( topic , row , stats )
265+ attach_document_to_topic ( topic , row , stats , report )
263266 end
264267 end
265268
266- def self . attach_document_to_topic ( topic , row , stats )
269+ def self . attach_document_to_topic ( topic , row , stats , report )
267270 file_path = get_file_path ( topic . state , topic . language . name )
268271 filename = row [ "File_Name" ]
269272
@@ -285,7 +288,7 @@ def self.attach_document_to_topic(topic, row, stats)
285288 end
286289
287290 rescue AzureFileShares ::Errors ::ApiError , URI ::InvalidURIError => e
288- handle_attachment_error ( topic , filename , e , stats )
291+ handle_attachment_error ( topic , filename , e , stats , report )
289292 end
290293 end
291294
@@ -298,12 +301,20 @@ def self.download_azure_file(file_path, filename)
298301 )
299302 end
300303
301- def self . handle_attachment_error ( topic , filename , error , stats )
304+ def self . handle_attachment_error ( topic , filename , error , stats , report )
302305 error_info = {
303306 topic : topic ,
304307 file : filename ,
305308 error : error . message ,
306309 }
310+
311+ ImportError . create (
312+ import_report_id : report . id ,
313+ topic_id : topic . id ,
314+ file_name : filename ,
315+ error_message : error_info
316+ )
317+
307318 stats [ :error_files ] << error_info
308319 puts "Error with file: #{ filename } for topic #{ topic . title } - #{ error . message } "
309320 end
@@ -331,12 +342,6 @@ def self.build_summary_stats(import_stats, csv_data, azure_files)
331342 }
332343 end
333344
334- def self . log_import_summary ( csv_rows , azure_files , importable_rows )
335- puts "CSV rows with topics: #{ csv_rows . size } "
336- puts "Azure files found: #{ azure_files . size } "
337- puts "Importable files: #{ importable_rows . size } "
338- end
339-
340345 def self . log_final_results ( stats )
341346 puts "Topics not found: #{ stats [ :topics_without_csv ] . size } "
342347 puts "Successful attachments: #{ stats [ :successful_attachments ] . size } "
0 commit comments