summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-02-12 20:38:24 +0100
committerDaniel Friesel <derf@finalrewind.org>2020-02-12 20:38:24 +0100
commita830acc69877e204e5136e0862959164691683ca (patch)
treee23d6b34ecd19529329323f36a0b0965aaa24c1c /lib
parentee38d48a555e0c9a8ccb4ca06d69566198f42714 (diff)
Handle cancelled arrival at checkout when departure at checkin is not cancelled
Diffstat (limited to 'lib')
-rwxr-xr-xlib/Travelynx.pm34
-rw-r--r--lib/Travelynx/Command/work.pm10
2 files changed, 42 insertions, 2 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm
index ea7ab58..2b34b99 100755
--- a/lib/Travelynx.pm
+++ b/lib/Travelynx.pm
@@ -817,7 +817,6 @@ sub startup {
arr_platform => $train->platform,
sched_arrival => $train->sched_arrival,
real_arrival => $train->arrival,
- cancelled => $train->arrival_is_cancelled ? 1 : 0,
route =>
$json->encode( [ $self->route_diff($train) ] ),
messages => $json->encode(
@@ -861,6 +860,39 @@ sub startup {
}
$self->invalidate_stats_cache( $cache_ts, $db, $uid );
}
+ elsif ( defined $train and $train->arrival_is_cancelled ) {
+
+ # This branch is only taken if the deparure was not cancelled,
+ # i.e., if the train was supposed to go here but got
+ # redirected or cancelled on the way and not from the start on.
+ # If the departure itself was cancelled, the user route is
+ # cancelled_from action -> 'cancelled journey' panel on main page
+ # -> cancelled_to action -> force checkout (causing the
+ # previous branch to be taken due to $force)
+ $journey->{edited} = 0;
+ $journey->{checkout_time} = $now;
+ $journey->{cancelled} = 1;
+ delete $journey->{data};
+ $db->insert( 'journeys', $journey );
+
+ $journey
+ = $db->select( 'in_transit', ['data'],
+ { user_id => $uid } )->expand->hash;
+ $journey->{data}{cancelled_destination} = $train->station;
+
+ $db->update(
+ 'in_transit',
+ {
+ checkout_station_id => undef,
+ checkout_time => undef,
+ arr_platform => undef,
+ sched_arrival => undef,
+ real_arrival => undef,
+ data => JSON->new->encode( $journey->{data} ),
+ },
+ { user_id => $uid }
+ );
+ }
$tx->commit;
};
diff --git a/lib/Travelynx/Command/work.pm b/lib/Travelynx/Command/work.pm
index 405716c..9658ff6 100644
--- a/lib/Travelynx/Command/work.pm
+++ b/lib/Travelynx/Command/work.pm
@@ -134,7 +134,15 @@ sub run {
checkout_station_id => $arr
}
);
- $self->app->add_route_timestamps( $uid, $train, 0 );
+ if ( $train->arrival_is_cancelled ) {
+
+ # check out (adds a cancelled journey and resets journey state
+ # to destination selection)
+ $self->app->checkout( $arr, 0, $uid );
+ }
+ else {
+ $self->app->add_route_timestamps( $uid, $train, 0 );
+ }
}
elsif ( $entry->{real_arr_ts} ) {
my ( undef, $error ) = $self->app->checkout( $arr, 1, $uid );