diff options
| -rw-r--r-- | lib/stif/codif_line_synchronization.rb | 10 |
1 files changed, 7 insertions, 3 deletions
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 |
