demarches-normaliennes/app/lib/recovery/revision_importer.rb
2024-08-22 09:26:48 +02:00

24 lines
701 B
Ruby

# frozen_string_literal: true
module Recovery
class RevisionImporter
attr_reader :revisions
def initialize(file_path: Recovery::RevisionExporter::FILE_PATH)
# rubocop:disable Security/MarshalLoad
@revisions = Marshal.load(File.read(file_path))
# rubocop:enable Security/MarshalLoad
end
def load
@revisions.each do |revision|
ProcedureRevisionTypeDeChamp.transaction do
revision.revision_types_de_champ.each do |coordinate|
ProcedureRevisionTypeDeChamp.upsert(coordinate.attributes)
TypeDeChamp.upsert(coordinate.type_de_champ.attributes.except('type_champs'))
end
end
end
end
end
end