From b211e0842acb4b35977bbb13de34d145a56bef4e Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 12 Dec 2019 19:21:39 +0100 Subject: permanently store wagon numbers and types when available --- lib/Travelynx.pm | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index 51fe12f..57e8e5b 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -2146,23 +2146,56 @@ sub startup { sub { my ($wagonorder) = @_; - my $res = $db->select( 'in_transit', ['data'], - { user_id => $uid } ); - my $res_h = $res->expand->hash; - my $data = $res_h->{data} // {}; + my $res = $db->select( + 'in_transit', + [ 'data', 'user_data' ], + { user_id => $uid } + ); + my $res_h = $res->expand->hash; + my $data = $res_h->{data} // {}; + my $user_data = $res_h->{user_data} // {}; if ($is_departure) { $data->{wagonorder_dep} = $wagonorder; + $user_data->{wagons} = []; + for my $group ( + @{ + $wagonorder->{data}{istformation} + {allFahrzeuggruppe} // [] + } + ) + { + for + my $wagon ( @{ $group->{allFahrzeug} // [] } ) + { + push( + @{ $user_data->{wagons} }, + { + id => $wagon->{fahrzeugnummer}, + number => + $wagon->{wagenordnungsnummer}, + type => $wagon->{fahrzeugtyp}, + } + ); + } + } + $db->update( + 'in_transit', + { + data => JSON->new->encode($data), + user_data => JSON->new->encode($user_data) + }, + { user_id => $uid } + ); } else { $data->{wagonorder_arr} = $wagonorder; + $db->update( + 'in_transit', + { data => JSON->new->encode($data) }, + { user_id => $uid } + ); } - - $db->update( - 'in_transit', - { data => JSON->new->encode($data) }, - { user_id => $uid } - ); } )->wait; } -- cgit v1.2.3