diff options
Diffstat (limited to 'lib/Travelynx/Model/Stations.pm')
-rw-r--r-- | lib/Travelynx/Model/Stations.pm | 63 |
1 files changed, 58 insertions, 5 deletions
diff --git a/lib/Travelynx/Model/Stations.pm b/lib/Travelynx/Model/Stations.pm index 174b3b4..bf35d1a 100644 --- a/lib/Travelynx/Model/Stations.pm +++ b/lib/Travelynx/Model/Stations.pm @@ -23,12 +23,15 @@ sub get_backend_id { # special case return 0; } - if ( $opt{hafas} and $self->{backend_id}{hafas}{ $opt{hafas} } ) { - return $self->{backend_id}{hafas}{ $opt{hafas} }; - } if ( $opt{dbris} and $self->{backend_id}{dbris}{ $opt{dbris} } ) { return $self->{backend_id}{dbris}{ $opt{dbris} }; } + if ( $opt{efa} and $self->{backend_id}{efa}{ $opt{efa} } ) { + return $self->{backend_id}{efa}{ $opt{efa} }; + } + if ( $opt{hafas} and $self->{backend_id}{hafas}{ $opt{hafas} } ) { + return $self->{backend_id}{hafas}{ $opt{hafas} }; + } if ( $opt{motis} and $self->{backend_id}{motis}{ $opt{motis} } ) { return $self->{backend_id}{motis}{ $opt{motis} }; } @@ -47,6 +50,17 @@ sub get_backend_id { )->hash->{id}; $self->{backend_id}{dbris}{ $opt{dbris} } = $backend_id; } + elsif ( $opt{efa} ) { + $backend_id = $db->select( + 'backends', + ['id'], + { + efa => 1, + name => $opt{efa} + } + )->hash->{id}; + $self->{backend_id}{efa}{ $opt{efa} } = $backend_id; + } elsif ( $opt{hafas} ) { $backend_id = $db->select( 'backends', @@ -100,7 +114,7 @@ sub get_backends { $opt{db} //= $self->{pg}->db; my $res = $opt{db}->select( 'backends', - [ 'id', 'name', 'iris', 'hafas', 'dbris', 'motis' ] ); + [ 'id', 'name', 'dbris', 'efa', 'hafas', 'iris', 'motis' ] ); my @ret; while ( my $row = $res->hash ) { @@ -109,9 +123,10 @@ sub get_backends { { id => $row->{id}, name => $row->{name}, - iris => $row->{iris}, dbris => $row->{dbris}, + efa => $row->{efa}, hafas => $row->{hafas}, + iris => $row->{iris}, motis => $row->{motis}, } ); @@ -166,6 +181,44 @@ sub add_or_update { return; } + if ( $opt{efa} ) { + if ( + my $s = $self->get_by_eva( + $stop->id_num, + db => $opt{db}, + backend_id => $opt{backend_id} + ) + ) + { + $opt{db}->update( + 'stations', + { + name => $stop->full_name, + lat => $stop->latlon->[0], + lon => $stop->latlon->[1], + archived => 0 + }, + { + eva => $stop->id_num, + source => $opt{backend_id} + } + ); + return; + } + $opt{db}->insert( + 'stations', + { + eva => $stop->id_num, + name => $stop->full_name, + lat => $stop->latlon->[0], + lon => $stop->latlon->[1], + source => $opt{backend_id}, + archived => 0 + } + ); + return; + } + if ( $opt{motis} ) { if ( my $s = $self->get_by_external_id( |