commit
629ca86897
1 changed files with 10 additions and 7 deletions
|
@ -1,7 +1,7 @@
|
||||||
namespace :after_party do
|
namespace :after_party do
|
||||||
desc 'Deployment task: backfill_experts_procedure_id_missing_on_avis'
|
desc 'Deployment task: backfill_experts_procedure_on_avis_2'
|
||||||
task backfill_experts_procedure_id_missing_on_avis: :environment do
|
task backfill_experts_procedure_on_avis_2: :environment do
|
||||||
puts "Running deploy task 'backfill_experts_procedure_id_missing_on_avis'"
|
puts "Running deploy task 'backfill_experts_procedure_on_avis_2'"
|
||||||
|
|
||||||
without_instructeur = Avis.where(experts_procedure_id: nil, answer: nil, instructeur_id: nil).where.not(email: nil)
|
without_instructeur = Avis.where(experts_procedure_id: nil, answer: nil, instructeur_id: nil).where.not(email: nil)
|
||||||
with_instructeur = Avis.where(experts_procedure_id: nil, answer: nil, email: nil).where.not(instructeur_id: nil)
|
with_instructeur = Avis.where(experts_procedure_id: nil, answer: nil, email: nil).where.not(instructeur_id: nil)
|
||||||
|
@ -10,10 +10,11 @@ namespace :after_party do
|
||||||
|
|
||||||
without_instructeur.find_each do |avis|
|
without_instructeur.find_each do |avis|
|
||||||
# if the avis email is valid then we create the associated expert
|
# if the avis email is valid then we create the associated expert
|
||||||
if Devise.email_regexp.match?(avis.email)
|
email = avis.email.strip
|
||||||
user = User.create_or_promote_to_expert(avis.email, SecureRandom.hex)
|
if Devise.email_regexp.match?(email)
|
||||||
|
user = User.create_or_promote_to_expert(email, SecureRandom.hex)
|
||||||
user.reload
|
user.reload
|
||||||
experts_procedure = ExpertsProcedure.find_or_create_by(procedure: avis.dossier.procedure, expert: user.expert)
|
experts_procedure = ExpertsProcedure.find_or_create_by!(procedure: avis.dossier.procedure, expert: user.expert)
|
||||||
avis.update_column(:experts_procedure_id, experts_procedure.id)
|
avis.update_column(:experts_procedure_id, experts_procedure.id)
|
||||||
end
|
end
|
||||||
progress.inc
|
progress.inc
|
||||||
|
@ -25,13 +26,15 @@ namespace :after_party do
|
||||||
if instructeur && instructeur.user
|
if instructeur && instructeur.user
|
||||||
user = User.create_or_promote_to_expert(instructeur.user.email, SecureRandom.hex)
|
user = User.create_or_promote_to_expert(instructeur.user.email, SecureRandom.hex)
|
||||||
user.reload
|
user.reload
|
||||||
experts_procedure = ExpertsProcedure.find_or_create_by(procedure: avis.dossier.procedure, expert: user.expert)
|
experts_procedure = ExpertsProcedure.find_or_create_by!(procedure: avis.dossier.procedure, expert: user.expert)
|
||||||
avis.update_column(:experts_procedure_id, experts_procedure.id)
|
avis.update_column(:experts_procedure_id, experts_procedure.id)
|
||||||
end
|
end
|
||||||
progress2.inc
|
progress2.inc
|
||||||
end
|
end
|
||||||
progress2.finish
|
progress2.finish
|
||||||
|
|
||||||
|
# Update task as completed. If you remove the line below, the task will
|
||||||
|
# run with every deploy (or every time you call after_party:run).
|
||||||
AfterParty::TaskRecord
|
AfterParty::TaskRecord
|
||||||
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
|
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
|
||||||
end
|
end
|
Loading…
Reference in a new issue