From d44016ac07ed4ccf1c1bc9f7e5810f6cf5c9322a Mon Sep 17 00:00:00 2001 From: guillaume imary Date: Wed, 13 Nov 2024 11:23:05 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Ajoute=20une=20transaction?= =?UTF-8?q?=20pour=20les=20questions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/import_export/questions/import.rb | 22 +++++++++----------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/app/models/import_export/questions/import.rb b/app/models/import_export/questions/import.rb index 5ce877c82..8975a3320 100644 --- a/app/models/import_export/questions/import.rb +++ b/app/models/import_export/questions/import.rb @@ -31,22 +31,20 @@ def process_rows(data) end end - # rubocop:disable Metrics/AbcSize def cree_question - @question = Question.new(type: @type) # On crée une nouvelle instance pour chaque ligne - @question.assign_attributes(libelle: @row[0], nom_technique: @row[1], description: @row[7]) - attache_fichier(@question.illustration, @row[2]) - @question.save! - cree_transcription(:intitule, @row[4], @row[3]) - cree_transcription(:modalite_reponse, @row[6], @row[5]) unless @question.sous_consigne? - update_champs_specifiques - @question + ActiveRecord::Base.transaction do + intialise_question + cree_transcription(:intitule, @row[4], @row[3]) + cree_transcription(:modalite_reponse, @row[6], @row[5]) unless @question.sous_consigne? + update_champs_specifiques + @question + end end - # rubocop:enable Metrics/AbcSize def intialise_question - @question.assign_attributes(libelle: @row[0], - nom_technique: @row[1], description: @row[7]) + @question = Question.new(type: @type) # On crée une nouvelle instance pour chaque ligne + @question.assign_attributes(libelle: @row[0], nom_technique: @row[1], + description: @row[7]) attache_fichier(@question.illustration, @row[2]) @question.save! end