Merge pull request #6839 from betagouv/main

2022-01-26-01
This commit is contained in:
Paul Chavard 2022-01-26 16:29:31 +01:00 committed by GitHub
commit e8583f2b21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 19 deletions

View file

@ -1,19 +0,0 @@
namespace :hotfix do
desc 'Fix attestation templates'
task attestation_templates: :environment do
attestation_templates = Rails.root.join('lib', 'tasks', 'attestation_templates.json')
file = File.read attestation_templates
json = JSON.parse file
progress = ProgressReport.new(json.size)
json.each do |row|
attestation_template = AttestationTemplate.find_by(id: row['id'])
procedure = Procedure.find_by(id: row['procedure_id'])
if attestation_template.present? && procedure.present?
attestation_template.update_column(:procedure_id, procedure.id)
end
progress.inc
end
progress.finish
end
end

22
lib/tasks/hotfix.rake Normal file
View file

@ -0,0 +1,22 @@
namespace :hotfix do
desc 'Fix dossiers attestations'
task dossiers_attestations: :environment do
dossiers = Dossier
.joins(procedure: :attestation_template)
.left_outer_joins(:attestation)
.where(attestation_templates: { activated: true },
attestations: { id: nil },
state: "accepte")
.where("dossiers.processed_at > '2022-01-24'")
progress = ProgressReport.new(dossiers.count)
dossiers.find_each do |dossier|
if dossier.attestation.blank?
dossier.attestation = dossier.build_attestation
dossier.save!
end
progress.inc
end
progress.finish
end
end