2022-12-04 17:52:01 +00:00
|
|
|
package Travelynx::Command::integritycheck;
|
2022-11-25 17:26:32 +00:00
|
|
|
|
2023-07-03 15:59:25 +00:00
|
|
|
# Copyright (C) 2022 Birte Kristina Friesel
|
2022-11-25 17:26:32 +00:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
use Mojo::Base 'Mojolicious::Command';
|
|
|
|
use List::Util qw();
|
|
|
|
use Travel::Status::DE::IRIS::Stations;
|
|
|
|
|
|
|
|
sub run {
|
|
|
|
my ($self) = @_;
|
2023-01-15 05:47:09 +00:00
|
|
|
my $found = 0;
|
|
|
|
my $db = $self->app->pg->db;
|
2022-11-25 17:26:32 +00:00
|
|
|
|
2023-01-15 05:47:09 +00:00
|
|
|
my $res1 = $db->query(
|
|
|
|
qq{
|
|
|
|
select checkin_station_id
|
|
|
|
from journeys
|
|
|
|
left join stations on journeys.checkin_station_id = stations.eva
|
|
|
|
where stations.eva is null;
|
|
|
|
}
|
|
|
|
);
|
2022-11-25 17:26:32 +00:00
|
|
|
|
2023-01-15 05:47:09 +00:00
|
|
|
my $res2 = $db->query(
|
|
|
|
qq{
|
|
|
|
select checkout_station_id
|
|
|
|
from journeys
|
|
|
|
left join stations on journeys.checkout_station_id = stations.eva
|
|
|
|
where stations.eva is null;
|
|
|
|
}
|
|
|
|
);
|
2022-11-25 17:26:32 +00:00
|
|
|
|
2023-01-15 05:47:09 +00:00
|
|
|
my %notified;
|
|
|
|
while ( my $row = $res1->hash ) {
|
|
|
|
my $eva = $row->{checkin_station_id};
|
|
|
|
if ( not $found ) {
|
|
|
|
$found = 1;
|
|
|
|
say
|
|
|
|
'Journeys in the travelynx database contain the following unknown EVA IDs.';
|
|
|
|
say '------------8<----------';
|
|
|
|
say 'Travel::Status::DE::IRIS v'
|
|
|
|
. $Travel::Status::DE::IRIS::Stations::VERSION;
|
|
|
|
}
|
|
|
|
if ( not $notified{$eva} ) {
|
|
|
|
say $eva;
|
|
|
|
$notified{$eva} = 1;
|
|
|
|
}
|
2022-11-25 17:26:32 +00:00
|
|
|
}
|
|
|
|
|
2023-01-15 05:47:09 +00:00
|
|
|
while ( my $row = $res2->hash ) {
|
|
|
|
my $eva = $row->{checkout_station_id};
|
|
|
|
if ( not $found ) {
|
|
|
|
$found = 1;
|
|
|
|
say
|
2022-12-04 19:57:27 +00:00
|
|
|
'Journeys in the travelynx database contain the following unknown EVA IDs.';
|
2023-01-15 05:47:09 +00:00
|
|
|
say '------------8<----------';
|
|
|
|
say 'Travel::Status::DE::IRIS v'
|
|
|
|
. $Travel::Status::DE::IRIS::Stations::VERSION;
|
|
|
|
}
|
|
|
|
if ( not $notified{$eva} ) {
|
2022-11-25 17:26:32 +00:00
|
|
|
say $eva;
|
2023-01-15 05:47:09 +00:00
|
|
|
$notified{$eva} = 1;
|
2022-11-25 17:26:32 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-15 05:47:09 +00:00
|
|
|
|
2022-12-04 19:57:27 +00:00
|
|
|
if ($found) {
|
|
|
|
say '------------8<----------';
|
|
|
|
say '';
|
|
|
|
$found = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $rename = $self->app->renamed_station;
|
|
|
|
|
2023-01-15 05:47:09 +00:00
|
|
|
my $res = $db->select( 'journeys', [ 'route', 'edited' ] )->expand;
|
2022-12-04 20:04:43 +00:00
|
|
|
while ( my $j = $res->hash ) {
|
2022-12-04 19:57:27 +00:00
|
|
|
if ( $j->{edited} & 0x0010 ) {
|
|
|
|
next;
|
|
|
|
}
|
2023-01-15 05:47:09 +00:00
|
|
|
my @stops = @{ $j->{route} // [] };
|
|
|
|
for my $stop (@stops) {
|
2022-12-04 19:57:27 +00:00
|
|
|
my $stop_name = $stop->[0];
|
2023-01-15 05:47:09 +00:00
|
|
|
if ( $rename->{ $stop->[0] } ) {
|
|
|
|
$stop->[0] = $rename->{ $stop->[0] };
|
2022-12-04 19:57:27 +00:00
|
|
|
}
|
2023-01-15 05:47:09 +00:00
|
|
|
}
|
|
|
|
my @unknown
|
|
|
|
= $self->app->stations->grep_unknown( map { $_->[0] } @stops );
|
|
|
|
for my $stop_name (@unknown) {
|
|
|
|
if ( not $notified{$stop_name} ) {
|
2022-12-04 19:57:27 +00:00
|
|
|
if ( not $found ) {
|
|
|
|
say
|
|
|
|
'Journeys in the travelynx database contain the following unknown route entries.';
|
|
|
|
say 'Note that this check ignores manual route entries.';
|
|
|
|
say 'All reports refer to routes obtained via HAFAS/IRIS.';
|
|
|
|
say '------------8<----------';
|
|
|
|
say 'Travel::Status::DE::IRIS v'
|
|
|
|
. $Travel::Status::DE::IRIS::Stations::VERSION;
|
|
|
|
$found = 1;
|
|
|
|
}
|
|
|
|
say $stop_name;
|
|
|
|
$notified{$stop_name} = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($found) {
|
|
|
|
say '------------8<----------';
|
|
|
|
say '';
|
|
|
|
}
|
2022-11-25 17:26:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|