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

Stations->get_by_names: backend_id is mandatory these days

parent 0a2fdea5
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -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(
+6 −3
Original line number Diff line number Diff line
@@ -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 ) {
+10 −5
Original line number Diff line number Diff line
@@ -445,8 +445,12 @@ sub update {

			# Otherwise, fetch stop IDs so that polylines remain usable
			if ( @new_route != @{ $opt{route} } ) {
				my %stop_id = map { $_->{name} => $_->{eva} }
				  $self->{stations}->get_by_names( @{ $opt{route} } );
				my %stop_id
				  = map { $_->{name} => $_->{eva} }
				  $self->{stations}->get_by_names(
					backend_id => $journey->{backend_id},
					names      => [ $opt{route} ]
				  );
				@new_route = map { [ $_, $stop_id{$_}, {} ] } @{ $opt{route} };
			}

@@ -1268,9 +1272,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 );
		}
+12 −7
Original line number Diff line number Diff line
@@ -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;
}