diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2019-12-12 19:21:39 +0100 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2019-12-12 19:21:39 +0100 |
commit | b211e0842acb4b35977bbb13de34d145a56bef4e (patch) | |
tree | b430d482fdf629cc3cc45bf2616ca3a92b717b50 /lib | |
parent | e6160d75de7a603ffba5c0489fc17fd240475961 (diff) |
permanently store wagon numbers and types when available
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/Travelynx.pm | 53 |
1 files 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; } |