demarches-normaliennes/lib/tasks/hotfix.rake

21 lines
603 B
Ruby
Raw Normal View History

namespace :hotfix do
desc 'Fix dossiers attestations'
task dossiers_attestations: :environment do
dossiers = Dossier
.joins(procedure: :attestation_template)
2023-04-19 12:03:08 +02:00
.where.missing(:attestation)
.where(attestation_templates: { activated: true }, 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