Merge pull request #882 from sgmap/regenerate_attestation_task
Rake: task to regenerate the attestation
This commit is contained in:
commit
1055c96c4d
1 changed files with 29 additions and 0 deletions
29
lib/tasks/2017_10_18_regenerate_attestation.rake
Normal file
29
lib/tasks/2017_10_18_regenerate_attestation.rake
Normal file
|
@ -0,0 +1,29 @@
|
|||
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)
|
||||
Procedure.unscoped do
|
||||
Dossier.unscoped do
|
||||
dossier = attestation.dossier
|
||||
procedure = dossier.procedure
|
||||
|
||||
puts "processing dossier #{dossier.id}"
|
||||
|
||||
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
|
Loading…
Reference in a new issue