diff options
| author | Edouard Maffert | 2016-08-01 12:11:43 +0200 |
|---|---|---|
| committer | Edouard Maffert | 2016-08-01 12:11:58 +0200 |
| commit | 4d0bbfcf7aa6cf8cb313954363d925a823756844 (patch) | |
| tree | 2038633ba48e210e3fa09a3c2a61dc111737db35 /lib | |
| parent | f16a41a7b7bde5a5913aad833fbfff3f0abf1504 (diff) | |
| download | chouette-core-4d0bbfcf7aa6cf8cb313954363d925a823756844.tar.bz2 | |
fix lines request and deactivated lines
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/stif/codif_line_synchronization.rb | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/lib/stif/codif_line_synchronization.rb b/lib/stif/codif_line_synchronization.rb index 0c4c6e91e..f14dc6f31 100644 --- a/lib/stif/codif_line_synchronization.rb +++ b/lib/stif/codif_line_synchronization.rb @@ -11,15 +11,16 @@ module Stif # TODO Check exceptions and status messages begin # Fetch Codifline operators and lines - client = Codifligne::API.new + client = Codifligne::API.new operators = client.operators - lines = client.lines + # 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 operators.map{ |o| create_or_update_company(o) } - lines.map{ |l| create_or_update_line(l) if first_sync || l.instance_variable_get(:@updated_at).to_date > last_sync.to_date} + lines.map{ |l| create_or_update_line(l) } delete_deprecated_companies(operators) - deactivate_deprecated_lines(lines) LineReferential.first.line_referential_sync.record_status "OK" rescue Exception => e @@ -41,7 +42,7 @@ module Stif name: api_line.name, objectid: api_line.stif_id, number: api_line.short_name, - deactivated: false + deactivated: (api_line.status == "inactive" ? true : false) } # Find Company @@ -59,11 +60,6 @@ module Stif Chouette::Company.where.not(objectid: ids).destroy_all end - def deactivate_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 |
