2019-05-16 15:26:58 +02:00
|
|
|
require Rails.root.join("lib", "tasks", "task_helper")
|
|
|
|
|
|
|
|
namespace :pieces_justificatives do
|
|
|
|
task migrate_procedure_to_champs: :environment do
|
|
|
|
procedure_id = ENV['PROCEDURE_ID']
|
2019-05-16 15:37:33 +02:00
|
|
|
procedure = Procedure.find(procedure_id)
|
|
|
|
|
2019-05-16 15:26:58 +02:00
|
|
|
service = PieceJustificativeToChampPieceJointeMigrationService.new
|
|
|
|
service.ensure_correct_storage_configuration!
|
2019-05-16 15:37:33 +02:00
|
|
|
|
|
|
|
progress = ProgressReport.new(service.number_of_champs_to_migrate(procedure))
|
|
|
|
|
|
|
|
service.convert_procedure_pjs_to_champ_pjs(procedure) do
|
|
|
|
progress.inc
|
|
|
|
end
|
|
|
|
|
|
|
|
progress.finish
|
2019-05-16 15:26:58 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
task migrate_procedures_range_to_champs: :environment do
|
|
|
|
if ENV['RANGE_START'].nil? || ENV['RANGE_END'].nil?
|
|
|
|
fail "RANGE_START and RANGE_END must be specified"
|
|
|
|
end
|
|
|
|
procedures_range = ENV['RANGE_START']..ENV['RANGE_END']
|
|
|
|
|
|
|
|
service = PieceJustificativeToChampPieceJointeMigrationService.new
|
|
|
|
service.ensure_correct_storage_configuration!
|
|
|
|
procedures_to_migrate = service.procedures_with_pjs_in_range(procedures_range)
|
|
|
|
|
2019-05-16 15:37:33 +02:00
|
|
|
total_number_of_champs_to_migrate = procedures_to_migrate
|
|
|
|
.map { |p| service.number_of_champs_to_migrate(p) }
|
|
|
|
.sum
|
|
|
|
progress = ProgressReport.new(total_number_of_champs_to_migrate)
|
|
|
|
|
2019-05-16 15:26:58 +02:00
|
|
|
procedures_to_migrate.find_each do |procedure|
|
|
|
|
rake_puts ''
|
|
|
|
rake_puts "Migrating procedure #{procedure.id}…"
|
|
|
|
|
2019-05-16 15:37:33 +02:00
|
|
|
service.convert_procedure_pjs_to_champ_pjs(procedure) do
|
|
|
|
progress.inc
|
|
|
|
end
|
2019-05-16 15:26:58 +02:00
|
|
|
end
|
2019-05-16 15:37:33 +02:00
|
|
|
|
|
|
|
progress.finish
|
2019-05-16 15:26:58 +02:00
|
|
|
end
|
|
|
|
end
|