add rake task for importing instructeurs from csv
Co-authored-by: sim <mail@simon.lehericey.net>
This commit is contained in:
parent
792b53beeb
commit
b4256f9560
1 changed files with 25 additions and 0 deletions
25
lib/tasks/instructeurs.rake
Normal file
25
lib/tasks/instructeurs.rake
Normal file
|
@ -0,0 +1,25 @@
|
|||
require Rails.root.join("lib", "tasks", "task_helper")
|
||||
|
||||
namespace :instructeurs do
|
||||
desc <<~EOD
|
||||
Import several instructeurs for a procedure
|
||||
rails instructeurs:import\[procedure_id,csv_path\]
|
||||
EOD
|
||||
task :import, [:procedure_id, :csv] => :environment do |_t, args|
|
||||
procedure_id = args[:procedure_id]
|
||||
csv = args[:csv]
|
||||
lines = CSV.readlines(csv, headers: true)
|
||||
|
||||
rake_puts "Import en cours..."
|
||||
|
||||
errors =
|
||||
InstructeursImportService.new.import(Procedure.find(procedure_id), lines)
|
||||
|
||||
if errors.present?
|
||||
rake_puts "Ces instructeurs n'ont pas pu être importés :"
|
||||
rake_puts errors
|
||||
end
|
||||
|
||||
rake_puts "Import terminé"
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue