demarches-normaliennes/app/jobs/tmp_dossiers_migrate_revisions_job.rb

23 lines
629 B
Ruby
Raw Normal View History

2020-06-26 11:38:25 +02:00
class TmpDossiersMigrateRevisionsJob < ApplicationJob
def perform(except)
dossiers = Dossier.with_discarded.where(revision_id: nil)
dossiers.where
.not(id: except)
.includes(procedure: [:draft_revision, :published_revision])
.limit(2000)
.find_each do |dossier|
if dossier.procedure.present?
dossier.revision = dossier.procedure.active_revision
dossier.save!(validate: false)
else
except << dossier.id
end
end
if dossiers.where.not(id: except).exists?
TmpDossiersMigrateRevisionsJob.perform_later(except)
end
end
end