demarches-normaliennes/lib/tasks/hotfix.rake
2024-08-22 09:26:48 +02:00

22 lines
634 B
Ruby

# frozen_string_literal: true
namespace :hotfix do
desc 'Fix dossiers attestations'
task dossiers_attestations: :environment do
dossiers = Dossier
.joins(procedure: :attestation_template)
.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