Bug 31143: (QA follow-up) Tidy

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Nick Clemens 2024-09-27 17:45:01 +00:00 committed by Katrin Fischer
parent b598154fbf
commit a900e9307b
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
2 changed files with 23 additions and 16 deletions

View File

@ -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;
}
}

View File

@ -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)");
}