Merge pull request #9057 from demarches-simplifiees/US/restore-dossier-kc
amelioration(recovery:import): meilleure log et gestion de edge cases
This commit is contained in:
commit
634257e242
2 changed files with 26 additions and 3 deletions
|
@ -9,10 +9,20 @@ module Recovery
|
||||||
end
|
end
|
||||||
|
|
||||||
def load
|
def load
|
||||||
@dossiers.map do |dossier|
|
@dossiers.each do |dossier|
|
||||||
|
if Dossier.exists?(dossier.id)
|
||||||
|
puts "Dossier #{dossier.id} already exists"
|
||||||
|
next
|
||||||
|
end
|
||||||
dossier.instance_variable_set :@new_record, true
|
dossier.instance_variable_set :@new_record, true
|
||||||
|
dossier_attributes = dossier.attributes.dup
|
||||||
|
|
||||||
Dossier.insert(dossier.attributes)
|
parent_dossier_id = dossier_attributes['parent_dossier_id']
|
||||||
|
if parent_dossier_id && !Dossier.exists?(id: parent_dossier_id)
|
||||||
|
dossier_attributes.delete('parent_dossier_id')
|
||||||
|
end
|
||||||
|
|
||||||
|
Dossier.insert(dossier_attributes)
|
||||||
|
|
||||||
if dossier.etablissement.present?
|
if dossier.etablissement.present?
|
||||||
Etablissement.insert(dossier.etablissement.attributes)
|
Etablissement.insert(dossier.etablissement.attributes)
|
||||||
|
@ -98,7 +108,7 @@ module Recovery
|
||||||
champ.geo_areas.each { GeoArea.insert(_1.attributes) }
|
champ.geo_areas.each { GeoArea.insert(_1.attributes) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
puts "imported dossier: #{dossier.id}"
|
puts "imported dossier #{dossier.id}: #{Dossier.exists?(dossier.id)}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -115,5 +115,18 @@ describe 'Recovery::LifeCycle' do
|
||||||
|
|
||||||
expect(reloaded_dossier.transfer_logs).to be_present
|
expect(reloaded_dossier.transfer_logs).to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'skip parent_dossier_id when dossier does not exists any more' do
|
||||||
|
parent = create(:dossier)
|
||||||
|
dossier.update!(parent_dossier_id: parent.id)
|
||||||
|
@dossier_ids = [dossier.id]
|
||||||
|
|
||||||
|
Recovery::Exporter.new(dossier_ids: @dossier_ids, file_path: fp).dump
|
||||||
|
Dossier.where(id: @dossier_ids).destroy_all
|
||||||
|
parent.destroy
|
||||||
|
Recovery::Importer.new(file_path: fp).load
|
||||||
|
|
||||||
|
expect(Dossier.count).to eq(1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue