2018-06-12 18:17:37 +02:00
|
|
|
require Rails.root.join("lib", "tasks", "task_helper")
|
|
|
|
|
2017-10-18 17:05:34 +02:00
|
|
|
namespace :'2017_10_18_regenerate_attestation' do
|
|
|
|
task set: :environment do
|
|
|
|
include ActiveSupport::Testing::TimeHelpers
|
|
|
|
|
|
|
|
if ENV['ATTESTATION_ID'].present?
|
|
|
|
regenerate_attestations(Attestation.find(ENV['ATTESTATION_ID']))
|
|
|
|
else
|
|
|
|
Attestation.all.each { |attestation| regenerate_attestations(attestation) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def regenerate_attestations(attestation)
|
2020-01-28 16:41:15 +01:00
|
|
|
Procedure.with_hidden do
|
2020-01-28 16:55:07 +01:00
|
|
|
Dossier.with_hidden do
|
2017-10-18 17:05:34 +02:00
|
|
|
dossier = attestation.dossier
|
|
|
|
procedure = dossier.procedure
|
|
|
|
|
2018-06-12 18:17:37 +02:00
|
|
|
rake_puts "processing dossier #{dossier.id}"
|
2017-10-18 17:05:34 +02:00
|
|
|
|
|
|
|
travel_to(dossier.processed_at) do
|
|
|
|
new_attestation = procedure.attestation_template.attestation_for(dossier)
|
|
|
|
attestation.delete
|
|
|
|
dossier.attestation = new_attestation
|
|
|
|
dossier.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|