Unverified Commit f1da50f9 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Fix worker for MOTIS checkins

Apparently, even after a check-in has been performed, subsequent worker runs
may encounter stop IDs that were not added to stations_external_ids by the
check-in process. So we need to add_or_update all stops we ecounter.
parent 9b6a3171
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -197,13 +197,15 @@ sub run {

						for my $stopover ( $journey->stopovers ) {
							if ( not defined $stopover->stop->{eva} ) {
								my $stop
								  = $self->app->stations->get_by_external_id(
									external_id => $stopover->stop->id,

								# Looks like MOTIS / transitous station IDs can change after the fact.
								# So let's be safe rather than sorry, even if this causes way too many calls to the slow path
								# (Stations::get_by_external_id uses string lookups).
								# This function call implicitly sets $stopover->stop->{eva} for MOTIS backends.
								$self->app->stations->add_or_update(
									stop  => $stopover->stop,
									motis => $entry->{backend_name},
								);

								$stopover->stop->{eva} = $stop->{eva};
							}
						}

+3 −2
Original line number Diff line number Diff line
@@ -120,6 +120,7 @@ sub get_backends {
	return @ret;
}

# Slow for MOTIS backends
sub add_or_update {
	my ( $self, %opt ) = @_;
	my $stop = $opt{stop};
@@ -188,8 +189,8 @@ sub add_or_update {
				}
			);

			# MOTIS backends do not provide a numeric ID, so we set our ID here.
			$stop->{eva} = $s->{eva};

			return;
		}

@@ -211,8 +212,8 @@ sub add_or_update {
			)
		);

		# MOTIS backends do not provide a numeric ID, so we set our ID here.
		$stop->{eva} = $s->hash->{eva};

		return;
	}