2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-05-15 11:41:38 +02:00
|
|
|
module Recovery
|
|
|
|
class Exporter
|
|
|
|
FILE_PATH = Rails.root.join('lib', 'data', 'export.dump')
|
|
|
|
|
2023-05-15 17:41:53 +02:00
|
|
|
attr_reader :dossiers, :file_path
|
2023-05-15 11:41:38 +02:00
|
|
|
def initialize(dossier_ids:, file_path: FILE_PATH)
|
|
|
|
dossier_with_data = Dossier.where(id: dossier_ids)
|
|
|
|
.preload(:user,
|
|
|
|
:individual,
|
2023-05-15 12:54:20 +02:00
|
|
|
:invites,
|
|
|
|
:traitements,
|
|
|
|
:transfer_logs,
|
2024-02-13 12:06:41 +01:00
|
|
|
commentaires: { piece_jointe_attachments: :blob },
|
2023-05-15 12:54:20 +02:00
|
|
|
avis: { introduction_file_attachment: :blob, piece_justificative_file_attachment: :blob },
|
|
|
|
dossier_operation_logs: { serialized_attachment: :blob },
|
|
|
|
attestation: { pdf_attachment: :blob },
|
|
|
|
justificatif_motivation_attachment: :blob,
|
|
|
|
etablissement: :exercices,
|
2023-05-15 11:41:38 +02:00
|
|
|
revision: :procedure)
|
2023-05-15 17:41:53 +02:00
|
|
|
@dossiers = DossierPreloader.new(dossier_with_data,
|
2024-05-15 10:49:27 +02:00
|
|
|
includes_for_champ: [:geo_areas, etablissement: :exercices],
|
2023-05-15 17:41:53 +02:00
|
|
|
includes_for_etablissement: [:exercices]).all
|
2023-05-15 11:41:38 +02:00
|
|
|
@file_path = file_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def dump
|
2023-05-15 17:41:53 +02:00
|
|
|
@file_path.binwrite(Marshal.dump(@dossiers))
|
2023-05-15 11:41:38 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|