From e270eb3a515d897b2157897e83bc5d4cdb670d62 Mon Sep 17 00:00:00 2001 From: Edouard Maffert Date: Mon, 1 Aug 2016 15:10:28 +0200 Subject: fix line synchronization --- lib/stif/codif_line_synchronization.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/stif/codif_line_synchronization.rb') diff --git a/lib/stif/codif_line_synchronization.rb b/lib/stif/codif_line_synchronization.rb index f14dc6f31..9a8a92bce 100644 --- a/lib/stif/codif_line_synchronization.rb +++ b/lib/stif/codif_line_synchronization.rb @@ -13,14 +13,13 @@ module Stif # Fetch Codifline operators and lines client = Codifligne::API.new operators = client.operators - # Get last sync date for lines if not first sync - date = first_sync ? 0 : last_sync.to_date.strftime("%d%m%Y") - lines = client.lines date: date + lines = client.lines operators.map{ |o| create_or_update_company(o) } lines.map{ |l| create_or_update_line(l) } delete_deprecated_companies(operators) + delete_deprecated_lines(lines) LineReferential.first.line_referential_sync.record_status "OK" rescue Exception => e @@ -60,6 +59,11 @@ module Stif Chouette::Company.where.not(objectid: ids).destroy_all end + def delete_deprecated_lines(lines) + ids = lines.map{ |l| l.stif_id }.to_a + Chouette::Line.where.not(objectid: ids).map { |l| l.deactivated = true ; l.save } + end + def save_or_update(params, klass) params[:line_referential] = LineReferential.first object = klass.where(objectid: params[:objectid]).first -- cgit v1.2.3