From da2333ca3e1ff4baf02a2cac285d3cdd8b9e74d3 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Fri, 5 Oct 2018 19:05:55 +0200 Subject: [PATCH] Rake task to change siret number --- lib/tasks/support.rake | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/tasks/support.rake b/lib/tasks/support.rake index e4832dd67..d889ecb17 100644 --- a/lib/tasks/support.rake +++ b/lib/tasks/support.rake @@ -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