From 6b4a82da32e28f48695e284f81931888bc2950e3 Mon Sep 17 00:00:00 2001
From: Daniel Friesel <derf@finalrewind.org>
Date: Sat, 4 Feb 2023 21:17:45 +0100
Subject: inconsistent journeys: link to journeys

---
 lib/Travelynx/Command/database.pm | 13 +++++++++++++
 lib/Travelynx/Model/Journeys.pm   | 10 ++++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)

(limited to 'lib')

diff --git a/lib/Travelynx/Command/database.pm b/lib/Travelynx/Command/database.pm
index 4b83208..a42f2f5 100644
--- a/lib/Travelynx/Command/database.pm
+++ b/lib/Travelynx/Command/database.pm
@@ -1287,6 +1287,19 @@ my @migrations = (
 			}
 		);
 	},
+
+	# v30 -> v31
+	# travelynx v1.29.17 introduces links to conflicting journeys.
+	# These require changes to statistics data.
+	sub {
+		my ($db) = @_;
+		$db->query(
+			qq{
+				truncate journey_stats;
+				update schema_version set version = 31;
+			}
+		);
+	},
 );
 
 sub sync_stations {
diff --git a/lib/Travelynx/Model/Journeys.pm b/lib/Travelynx/Model/Journeys.pm
index defff0b..1239266 100755
--- a/lib/Travelynx/Model/Journeys.pm
+++ b/lib/Travelynx/Model/Journeys.pm
@@ -1486,8 +1486,14 @@ sub compute_stats {
 			and $next_departure - $journey->{rt_arr_ts} < ( 60 * 60 ) )
 		{
 			if ( $next_departure - $journey->{rt_arr_ts} < 0 ) {
-				push( @inconsistencies,
-					epoch_to_dt($next_departure)->strftime('%d.%m.%Y %H:%M') );
+				push(
+					@inconsistencies,
+					[
+						epoch_to_dt($next_departure)
+						  ->strftime('%d.%m.%Y %H:%M'),
+						$journey->{id}
+					]
+				);
 			}
 			else {
 				$interchange_real
-- 
cgit v1.2.3