From e9115b10b5acf1847a25af1168c8c2824e2b7636 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 15 May 2023 11:41:38 +0200 Subject: [PATCH] =?UTF-8?q?correctif(data.kc):=20re-import=20les=20donn?= =?UTF-8?q?=C3=A9es=20kc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/lib/recovery/exporter.rb | 21 ++++++++++++ app/lib/recovery/importer.rb | 17 ++++++++++ app/lib/recovery/life_cycle.rb | 33 ++++++++++++++++++ spec/fixtures/recovery/export.dump | Bin 0 -> 22069 bytes spec/lib/recovery/exporter_spec.rb | 48 +++++++++++++++++++++++++++ spec/lib/recovery/importer_spec.rb | 16 +++++++++ spec/lib/recovery/life_cycle_spec.rb | 8 +++++ 7 files changed, 143 insertions(+) create mode 100644 app/lib/recovery/exporter.rb create mode 100644 app/lib/recovery/importer.rb create mode 100644 app/lib/recovery/life_cycle.rb create mode 100644 spec/fixtures/recovery/export.dump create mode 100644 spec/lib/recovery/exporter_spec.rb create mode 100644 spec/lib/recovery/importer_spec.rb create mode 100644 spec/lib/recovery/life_cycle_spec.rb diff --git a/app/lib/recovery/exporter.rb b/app/lib/recovery/exporter.rb new file mode 100644 index 000000000..e397feb82 --- /dev/null +++ b/app/lib/recovery/exporter.rb @@ -0,0 +1,21 @@ +module Recovery + class Exporter + FILE_PATH = Rails.root.join('lib', 'data', 'export.dump') + + attr_reader :dossiers + def initialize(dossier_ids:, file_path: FILE_PATH) + dossier_with_data = Dossier.where(id: dossier_ids) + .preload(:user, + :individual, + :etablissement, + revision: :procedure) + @dossiers = DossierPreloader.new(dossier_with_data).all + @file_path = file_path + end + + def dump + File.open(@file_path, 'wb') { _1.write(Marshal.dump(@dossiers)) } + end + end +end + diff --git a/app/lib/recovery/importer.rb b/app/lib/recovery/importer.rb new file mode 100644 index 000000000..c2f2543b8 --- /dev/null +++ b/app/lib/recovery/importer.rb @@ -0,0 +1,17 @@ +module Recovery + class Importer + attr_reader :dossiers + + def initialize(file_path: Recovery::Exporter::FILE_PATH) + @dossiers = Marshal.load(File.read(file_path)) + end + + def load + @dossiers.map do |dossier| + dossier.instance_variable_set :@new_record, true + dossier.save! + end + end + end +end + diff --git a/app/lib/recovery/life_cycle.rb b/app/lib/recovery/life_cycle.rb new file mode 100644 index 000000000..ed2bf83e4 --- /dev/null +++ b/app/lib/recovery/life_cycle.rb @@ -0,0 +1,33 @@ +module Recovery + class LifeCycle + def initialize(dossier_ids:) + @dossier_ids = dossier_ids + end + + def load_export_destroy_and_import + export_dossiers + destroy_dossiers + import_dossiers + end + + def exporter + @exporter ||= Recovery::Exporter.new(dossier_ids: @dossier_ids) + end + + def importer + @importer ||= Importer.new() + end + + def export_dossiers + exporter.dump + end + + def destroy_dossiers + Dossier.where(id: @dossier_ids).destroy_all + end + + def import_dossiers + importer.load + end + end +end diff --git a/spec/fixtures/recovery/export.dump b/spec/fixtures/recovery/export.dump new file mode 100644 index 0000000000000000000000000000000000000000..983cf88b907156094a395add6a8662cfd159aade GIT binary patch literal 22069 zcmcgzd5|1edEah})!vt69V^LNuZ3@~XSK2=ciZ@_C9SkVhh^_Ulh`3z*L8T~@fHC;MR|v%AN?Z<9QpFz>Whlo*DcHmi<02Fk<)pw|CIrl3Lw?^o zx?lIqtd68msb{;tcYp8uzV}^kMcd5E!0Or+grVH6Zmqg)rvn` zt9oHz4UcE5{(^TP$aw|J+V9@8IIc>Mc-1a@QPn8ny3WD zU2fH#bwjVi>R=_e=&^QdBU^9_HP4y#=7NgnR2R#hlXb(YZ>}*=i@pPEbE4BJz$|OB zRQ2*+rQPafWz5_U{h*YwI$4-?3m&}`{Gwm=+woR$OL_FtaSQ!zv)aA8vxO}8Bwc?d4e&{)O2D1*j z^~zODBW$(Xrvkg9-R@+)c2~yk4y+r*5^mu*wyd2&spJ8%L1{eamaASRw5*$hu$r%U zM-K0|tV5H#ENi?{aTnXIZWh*N1tKnJfQTd5t5Tj&TCLQ)$>G*24Ug&0xrL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