From 7d915fbab1f121f90a3d3493b96d2b5837e2a67e Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 17 Oct 2018 19:56:12 +0000 Subject: [PATCH] Bug 21591: Check for record level item type issues too To test: 1 - sudo koha-mysql kohadev 2 - UPDATE biblioitems SET itemtype = NULL where biblionumber = 1 3 - UPDATE items SET itype = NULL where biblionumber = 1 4 - perl misc/maintenance/search_for_data_inconsistencies.pl 5 - Notice warnings 6 - Apply patch 7 - Undefined itemtype on bibliolevel is now warned 7 - Test also with itype="" Signed-off-by: David Nind Signed-off-by: Jonathan Druart Signed-off-by: Jonathan Druart (cherry picked from commit 6beda5cf1d1bb76ac692f5443e4b75f727c9c4ba) Signed-off-by: Lucas Gass --- .../search_for_data_inconsistencies.pl | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/misc/maintenance/search_for_data_inconsistencies.pl b/misc/maintenance/search_for_data_inconsistencies.pl index fd66200985..8f4014529e 100755 --- a/misc/maintenance/search_for_data_inconsistencies.pl +++ b/misc/maintenance/search_for_data_inconsistencies.pl @@ -55,14 +55,21 @@ use C4::Biblio; { if ( C4::Context->preference('item-level_itypes') ) { - my $items_without_itype = Koha::Items->search( { itype => undef } ); + my $items_without_itype = Koha::Items->search( { -or => [itype => undef,itype => ''] } ); if ( $items_without_itype->count ) { new_section("Items do not have itype defined"); while ( my $item = $items_without_itype->next ) { - new_item( - sprintf "Item with itemnumber=%s does not have a itype value, biblio's item type will be used (%s)", - $item->itemnumber, $item->biblioitem->itemtype - ); + if (defined $item->biblioitem->itemtype && $item->biblioitem->itemtype ne '' ) { + new_item( + sprintf "Item with itemnumber=%s does not have a itype value, biblio's item type will be used (%s)", + $item->itemnumber, $item->biblioitem->itemtype + ); + } else { + new_item( + sprintf "Item with itemnumber=%s does not have a itype value, additionally no item type defined for biblionumber=%s", + $item->itemnumber, $item->biblioitem->biblionumber + ); + } } new_hint("The system preference item-level_itypes expects item types to be defined at item level"); } @@ -83,7 +90,7 @@ use C4::Biblio; my @itemtypes = Koha::ItemTypes->search->get_column('itemtype'); if ( C4::Context->preference('item-level_itypes') ) { - my $items_with_invalid_itype = Koha::Items->search( { itype => { not_in => \@itemtypes } } ); + my $items_with_invalid_itype = Koha::Items->search( { -and => [itype => { not_in => \@itemtypes }, itype => { '!=' => '' }] } ); if ( $items_with_invalid_itype->count ) { new_section("Items have invalid itype defined"); while ( my $item = $items_with_invalid_itype->next ) { -- 2.39.5