diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2020-01-30 18:06:04 +0100 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2020-01-30 18:06:04 +0100 |
commit | 7e92e6b5d454ca61c77ed4ee217d179fc0038459 (patch) | |
tree | ec4860ce7d8937384e4d5ce4ae2cb50729739f76 | |
parent | dadb0f6637d92a661fda26f33121750d736d5e6d (diff) |
retroactively add polylines to non-polyline journeys1.14.2
-rw-r--r-- | lib/Travelynx/Command/maintenance.pm | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/Travelynx/Command/maintenance.pm b/lib/Travelynx/Command/maintenance.pm index 5cbf982..a70d42a 100644 --- a/lib/Travelynx/Command/maintenance.pm +++ b/lib/Travelynx/Command/maintenance.pm @@ -128,6 +128,50 @@ sub run { } $tx->commit; + + # Add estimated polylines to journeys logged before 2020-01-28 + + $tx = $db->begin; + + say 'Adding polylines to journeys logged before 2020-01-28'; + my $no_polyline + = $db->select( 'journeys', 'count(*) as count', { polyline_id => undef } ) + ->hash; + say "Checking $no_polyline->{count} journeys ..."; + + for my $journey ( + $db->select( 'journeys', [ 'id', 'route' ], { polyline_id => undef } ) + ->hashes->each ) + { + my $ref = $db->select( + 'journeys', + [ 'id', 'polyline_id' ], + { + route => $journey->{route}, + polyline_id => { '!=', undef } + }, + { limit => 1 } + )->hash; + if ($ref) { + my $rows = $db->update( + 'journeys', + { polyline_id => $ref->{polyline_id} }, + { id => $journey->{id} } + )->rows; + if ( $rows != 1 ) { + say STDERR +"Database update returned $rows rows, expected 1. Rollback and abort."; + exit(1); + } + } + } + + my $remaining + = $db->select( 'journeys', 'count(*) as count', { polyline_id => undef } ) + ->hash; + say "Done! Remaining journeys without polyline: " . $remaining->{count}; + + $tx->commit; } 1; |