diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2023-08-13 12:51:15 +0200 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2023-08-13 12:51:15 +0200 |
commit | 0604dd80f8b79233279093d14b7a2c55f77740ca (patch) | |
tree | c09ad99a97e1273fac67dd2aa26132018df5090e /lib/Travelynx/Model/Stations.pm | |
parent | 944688cfff5ee4c886adbe856889ab1e40bd58ac (diff) |
WIP: HAFAS support
Diffstat (limited to 'lib/Travelynx/Model/Stations.pm')
-rw-r--r-- | lib/Travelynx/Model/Stations.pm | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/Travelynx/Model/Stations.pm b/lib/Travelynx/Model/Stations.pm index af318ee..75b4174 100644 --- a/lib/Travelynx/Model/Stations.pm +++ b/lib/Travelynx/Model/Stations.pm @@ -14,6 +14,42 @@ sub new { return bless( \%opt, $class ); } +sub add_or_update { + my ( $self, %opt ) = @_; + my $stop = $opt{stop}; + my $source = 1; + my $db = $opt{db} // $self->{pg}->db; + + if ( my $s = $self->get_by_eva( $stop->eva, db => $db ) ) { + if ( $source == 1 and $s->{source} == 0 and not $s->{archived} ) { + return; + } + $db->update( + 'stations', + { + name => $stop->name, + lat => $stop->lat, + lon => $stop->lon, + source => $source, + archived => 0 + }, + { eva => $stop->eva } + ); + return; + } + $db->insert( + 'stations', + { + eva => $stop->eva, + name => $stop->name, + lat => $stop->lat, + lon => $stop->lon, + source => $source, + archived => 0 + } + ); +} + # Fast sub get_by_eva { my ( $self, $eva, %opt ) = @_; |