diff options
| author | Michel Etienne | 2014-10-02 11:06:56 +0200 |
|---|---|---|
| committer | Michel Etienne | 2014-10-02 11:06:56 +0200 |
| commit | d3df2620104289a1473ffca300685ad95e1edd98 (patch) | |
| tree | e63036e5c792a8e34acb6bb1758cebb3dce908b1 | |
| parent | ad37841236153979c9d2ad82c613c2b69c4ffbb6 (diff) | |
| download | chouette-core-d3df2620104289a1473ffca300685ad95e1edd98.tar.bz2 | |
proctect vehicle journey import against empty rows at end of file , Mantis 29014
| -rw-r--r-- | app/models/vehicle_journey_import.rb | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/app/models/vehicle_journey_import.rb b/app/models/vehicle_journey_import.rb index 42cc24244..20faef6cc 100644 --- a/app/models/vehicle_journey_import.rb +++ b/app/models/vehicle_journey_import.rb @@ -105,16 +105,21 @@ class VehicleJourneyImport first_stop_row_index = 7 stop_point_ids = first_column[first_stop_row_index..spreadsheet.last_row].map(&:to_i) - same_stop_points = route.stop_points.collect(&:id) == stop_point_ids + # blank lines at end of file will produce id = 0 ; ignore them + last_stop_row_index = stop_point_ids.length + 6 + while stop_point_ids.last == 0 + stop_point_ids = stop_point_ids[0..-2] + last_stop_row_index -= 1 + end - unless same_stop_points + unless route.stop_points.collect(&:id) == stop_point_ids errors.add :base, I18n.t("vehicle_journey_imports.errors.not_same_stop_points", :route => route.id) raise end (3..spreadsheet.last_column).each do |i| vehicle_journey_id = spreadsheet.column(i)[0] - hours_by_stop_point_ids = Hash[[stop_point_ids, spreadsheet.column(i)[first_stop_row_index..spreadsheet.last_row]].transpose] + hours_by_stop_point_ids = Hash[[stop_point_ids, spreadsheet.column(i)[first_stop_row_index..last_stop_row_index]].transpose] journey_pattern = find_journey_pattern_schedule(i,hours_by_stop_point_ids) |
