From 6e12cba512043ed779ec2433a8c4d01a0fc0b678 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 7 Oct 2025 16:10:51 +0200 Subject: [PATCH] Bug 40777: Introduce Koha::Database::DataInconsistency --- Koha/Database/DataInconsistency.pm | 42 +++++++++++++++++++ .../search_for_data_inconsistencies.pl | 21 ++++------ 2 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 Koha/Database/DataInconsistency.pm diff --git a/Koha/Database/DataInconsistency.pm b/Koha/Database/DataInconsistency.pm new file mode 100644 index 00000000000..9f67e48f1b4 --- /dev/null +++ b/Koha/Database/DataInconsistency.pm @@ -0,0 +1,42 @@ +package Koha::Database::DataInconsistency; + +use Modern::Perl; +use Koha::I18N qw( __x ); + +sub item_library { + my ( $self, $items ) = @_; + + $items = $items->search( { -or => { homebranch => undef, holdingbranch => undef } } ); + my @errors; + while ( my $item = $items->next ) { + if ( not $item->homebranch and not $item->holdingbranch ) { + push @errors, + __x( + "Item with itemnumber={itemnumber} does not have homebranch and holdingbranch defined", + itemnumber => $item->itemnumber + ); + } elsif ( not $item->homebranch ) { + push @errors, + __x( + "Item with itemnumber={itemnumber} does not have homebranch defined", + itemnumber => $item->itemnumber + ); + } else { + push @errors, + __x( + "Item with itemnumber={itemnumber} does not have holdingbranch defined", + itemnumber => $item->itemnumber + ); + } + } + return @errors; +} + +sub for_biblio { + my ( $self, $biblio ) = @_; + my @errors; + push @errors, $self->item_library( $biblio->items ); + return @errors; +} + +1; diff --git a/misc/maintenance/search_for_data_inconsistencies.pl b/misc/maintenance/search_for_data_inconsistencies.pl index 66f949ad6a8..37be69475c9 100755 --- a/misc/maintenance/search_for_data_inconsistencies.pl +++ b/misc/maintenance/search_for_data_inconsistencies.pl @@ -27,23 +27,18 @@ use Koha::Items; use Koha::ItemTypes; use Koha::Patrons; use C4::Biblio qw( GetMarcFromKohaField ); +use Koha::Database::DataInconsistency; { - my $items = Koha::Items->search( { -or => { homebranch => undef, holdingbranch => undef } } ); - if ( $items->count ) { new_section("Not defined items.homebranch and/or items.holdingbranch") } - while ( my $item = $items->next ) { - if ( not $item->homebranch and not $item->holdingbranch ) { - new_item( - sprintf "Item with itemnumber=%s does not have homebranch and holdingbranch defined", - $item->itemnumber - ); - } elsif ( not $item->homebranch ) { - new_item( sprintf "Item with itemnumber=%s does not have homebranch defined", $item->itemnumber ); - } else { - new_item( sprintf "Item with itemnumber=%s does not have holdingbranch defined", $item->itemnumber ); + my $items = Koha::Items->search; + my @errors = Koha::Database::DataInconsistency->item_library($items); + if (@errors) { + new_section("Not defined items.homebranch and/or items.holdingbranch"); + for my $error (@errors) { + new_item($error); } } - if ( $items->count ) { new_hint("Edit these items and set valid homebranch and/or holdingbranch") } + if (@errors) { new_hint("Edit these items and set valid homebranch and/or holdingbranch") } } { -- 2.34.1