Rake task to change siret number

This commit is contained in:
Frederic Merizen 2018-10-05 19:05:55 +02:00
parent 93183aae64
commit da2333ca3e

View file

@ -48,4 +48,26 @@ namespace :support do
user.dossiers.each(&:delete_and_keep_track)
user.destroy
end
desc <<~EOD
Change the SIRET for a given dossier (specified by DOSSIER_ID)
EOD
task update_dossier_siret: :environment do
siret_number = ENV['SIRET']
dossier_id = ENV['DOSSIER_ID']
if siret_number.nil?
fail "Must specify a SIRET"
end
siret_number = siret_number.dup # Unfreeze the string
siret = Siret.new(siret: siret_number)
if siret.invalid?
fail siret.errors.full_messages.to_sentence
end
dossier = Dossier.find(dossier_id)
EtablissementUpdateJob.perform_now(dossier, siret_number)
end
end