From a900e9307bd2b497bbaa6619de4098b2ea519626 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 27 Sep 2024 17:45:01 +0000 Subject: [PATCH] Bug 31143: (QA follow-up) Tidy Signed-off-by: Nick Clemens Signed-off-by: Katrin Fischer --- misc/maintenance/fix_invalid_dates.pl | 26 +++++++++++-------- .../search_for_data_inconsistencies.pl | 13 ++++++---- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/misc/maintenance/fix_invalid_dates.pl b/misc/maintenance/fix_invalid_dates.pl index a7f43b671d..2da8b1c457 100755 --- a/misc/maintenance/fix_invalid_dates.pl +++ b/misc/maintenance/fix_invalid_dates.pl @@ -18,9 +18,9 @@ use Modern::Perl; use C4::Context; -use C4::Log qw(cronlogaction); +use C4::Log qw(cronlogaction); use Getopt::Long qw( GetOptions ); -use Pod::Usage qw( pod2usage ); +use Pod::Usage qw( pod2usage ); use Koha::Logger; use Koha::DateUtils qw( dt_from_string ); use Koha::Script -cron; @@ -28,38 +28,42 @@ use Data::Dumper; use Koha::Database; my $verbose = 0; -my $doit = 0; +my $doit = 0; GetOptions( - 'v|verbose' => \$verbose, - 'c|confirm' => \$doit, + 'v|verbose' => \$verbose, + 'c|confirm' => \$doit, ); my $schema = Koha::Database->new->schema; + # Loop over all the DBIx::Class classes -for my $class ( sort values %{$schema->{class_mappings}} ) { +for my $class ( sort values %{ $schema->{class_mappings} } ) { + # Retrieve the resultset so we can access the columns info - my $rs = $schema->resultset($class); + my $rs = $schema->resultset($class); my $columns = $rs->result_source->columns_info; # Loop over the columns while ( my ( $column, $info ) = each %$columns ) { + # Next if data type is not date/datetime/timestamp my $data_type = $info->{data_type}; next unless grep { $data_type =~ m{^$_$} } qw( timestamp datetime date ); # Count the invalid dates - my $invalid_dates = $rs->search({ $column => '0000-00-00' })->count; + my $invalid_dates = $rs->search( { $column => '0000-00-00' } )->count; next unless $invalid_dates; - if ($verbose) { + if ($verbose) { say sprintf "Column %s.%s contains %s invalid dates", $rs->result_source->name, $column, $invalid_dates; } if ($doit) { - $rs->search({ $column => '0000-00-00' })->update({ $column => undef }); - say sprintf "Column %s.%s contains %s invalid dates that have been fixed", $rs->result_source->name, $column, $invalid_dates; + $rs->search( { $column => '0000-00-00' } )->update( { $column => undef } ); + say sprintf "Column %s.%s contains %s invalid dates that have been fixed", $rs->result_source->name, + $column, $invalid_dates; } } diff --git a/misc/maintenance/search_for_data_inconsistencies.pl b/misc/maintenance/search_for_data_inconsistencies.pl index ed29e4134f..4c0eddf792 100755 --- a/misc/maintenance/search_for_data_inconsistencies.pl +++ b/misc/maintenance/search_for_data_inconsistencies.pl @@ -331,25 +331,28 @@ use C4::Biblio qw( GetMarcFromKohaField ); my $schema = Koha::Database->new->schema; # Loop over all the DBIx::Class classes - for my $class ( sort values %{$schema->{class_mappings}} ) { + for my $class ( sort values %{ $schema->{class_mappings} } ) { + # Retrieve the resultset so we can access the columns info - my $rs = $schema->resultset($class); + my $rs = $schema->resultset($class); my $columns = $rs->result_source->columns_info; # Loop over the columns while ( my ( $column, $info ) = each %$columns ) { + # Next if data type is not date/datetime/timestamp my $data_type = $info->{data_type}; next unless grep { $data_type =~ m{^$_$} } qw( timestamp datetime date ); # Count the invalid dates - my $invalid_dates = $rs->search({ $column => '0000-00-00' })->count; + my $invalid_dates = $rs->search( { $column => '0000-00-00' } )->count; next unless $invalid_dates; - new_section("Column " . $rs->result_source->name . "." . $column . " contains $invalid_dates invalid dates"); + new_section( + "Column " . $rs->result_source->name . "." . $column . " contains $invalid_dates invalid dates" ); - if ($invalid_dates > 0) { + if ( $invalid_dates > 0 ) { new_hint("You may change the dates with script: misc/cronjobs/fix_invalid_dates.pl (-c -v)"); } -- 2.39.5