diff options
-rwxr-xr-x | lib/Travelynx.pm | 4 | ||||
-rw-r--r-- | lib/Travelynx/Command/integritycheck.pm | 9 | ||||
-rwxr-xr-x | lib/Travelynx/Model/Journeys.pm | 28 | ||||
-rw-r--r-- | lib/Travelynx/Model/Stations.pm | 19 |
4 files changed, 43 insertions, 17 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index d8e1cf4..a56dca0 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -1516,7 +1516,9 @@ sub startup { if ($has_arrived) { my @unknown_stations = $self->stations->grep_unknown( - $train->route ); + backend_id => $user->{backend_id}, + names => [ $train->route ] + ); if (@unknown_stations) { $self->app->log->warn( sprintf( diff --git a/lib/Travelynx/Command/integritycheck.pm b/lib/Travelynx/Command/integritycheck.pm index be5fe71..907d484 100644 --- a/lib/Travelynx/Command/integritycheck.pm +++ b/lib/Travelynx/Command/integritycheck.pm @@ -76,7 +76,8 @@ sub run { my %notified; my $rename = $self->app->renamed_station; - my $res = $db->select( 'journeys', [ 'route', 'edited' ] )->expand; + my $res = $db->select( 'journeys', [ 'backend_id', 'route', 'edited' ] ) + ->expand; while ( my $j = $res->hash ) { if ( $j->{edited} & 0x0010 ) { @@ -89,8 +90,10 @@ sub run { $stop->[0] = $rename->{ $stop->[0] }; } } - my @unknown - = $self->app->stations->grep_unknown( map { $_->[0] } @stops ); + my @unknown = $self->app->stations->grep_unknown( + backend_id => $j->{backend_id}, + names => [ map { $_->[0] } @stops ] + ); for my $stop_name (@unknown) { if ( not $notified{$stop_name} ) { if ( not $found ) { diff --git a/lib/Travelynx/Model/Journeys.pm b/lib/Travelynx/Model/Journeys.pm index 0ee436a..a6061e6 100755 --- a/lib/Travelynx/Model/Journeys.pm +++ b/lib/Travelynx/Model/Journeys.pm @@ -443,10 +443,25 @@ sub update { } } - # Otherwise, we need to fetch stop IDs so that polylines remain usable - # (This is still TODO) + # Otherwise, fetch stop IDs so that polylines remain usable if ( @new_route != @{ $opt{route} } ) { - @new_route = map { [ $_, undef, {} ] } @{ $opt{route} }; + my %stop + = map { $_->{name} => $_ } $self->{stations}->get_by_names( + backend_id => $journey->{backend_id}, + names => [ $opt{route} ] + ); + @new_route = map { + [ + $_, + $stop{$_}{eva}, + defined $stop{$_}{eva} + ? { + lat => $stop{$_}{lat}, + lon => $stop{$_}{lon} + } + : {} + ] + } @{ $opt{route} }; } $rows = $db->update( @@ -1267,9 +1282,10 @@ sub sanity_check { . ' Stimmt das wirklich?'; } if ( $journey->{edited} & 0x0010 and not $lax ) { - my @unknown_stations - = $self->{stations} - ->grep_unknown( map { $_->[0] } @{ $journey->{route} } ); + my @unknown_stations = $self->{stations}->grep_unknown( + backend_id => $journey->{backend_id}, + names => [ map { $_->[0] } @{ $journey->{route} } ] + ); if (@unknown_stations) { return 'Unbekannte Station(en): ' . join( ', ', @unknown_stations ); } diff --git a/lib/Travelynx/Model/Stations.pm b/lib/Travelynx/Model/Stations.pm index c6d9730..5316118 100644 --- a/lib/Travelynx/Model/Stations.pm +++ b/lib/Travelynx/Model/Stations.pm @@ -461,11 +461,16 @@ sub get_by_name { # Slow sub get_by_names { - my ( $self, @names ) = @_; + my ( $self, %opt ) = @_; - my @ret - = $self->{pg}->db->select( 'stations', '*', { name => { '=', \@names } } ) - ->hashes->each; + my @ret = $self->{pg}->db->select( + 'stations', + '*', + { + name => { '=', $opt{names} }, + source => $opt{backend_id} + } + )->hashes->each; return @ret; } @@ -506,10 +511,10 @@ sub search { # Slow sub grep_unknown { - my ( $self, @stations ) = @_; + my ( $self, %opt ) = @_; - my %station = map { $_->{name} => 1 } $self->get_by_names(@stations); - my @unknown_stations = grep { not $station{$_} } @stations; + my %station = map { $_->{name} => 1 } $self->get_by_names(%opt); + my @unknown_stations = grep { not $station{$_} } @{ $opt{names} }; return @unknown_stations; } |