From f2d40e1c691efff1a2b6c08e929b0f2612cf3dc1 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 21 Mar 2025 16:35:15 +0000 Subject: [PATCH] Bug 39413: Add a check for item fields in MARC records to data inconsistencies script This patch adds a new test to the data inconsistencies script to report where MARC records contain item fields. These may not cause issues in Koha, however, in discovery harvests they have eben found to create errors To test: 1 - Follow test plan on bug 39412 to generate records with item tags 2 - perl misc/maintenance/search_for_data_inconsistencies.pl 3 - Note new section and hint on how to fix 4 - perl misc/maintenance/touch_all_biblios.pl 5 - repeat 2 6 - Errors cleared Signed-off-by: Magnus Enger Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- .../search_for_data_inconsistencies.pl | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/misc/maintenance/search_for_data_inconsistencies.pl b/misc/maintenance/search_for_data_inconsistencies.pl index ebe3204ed3..72d9656118 100755 --- a/misc/maintenance/search_for_data_inconsistencies.pl +++ b/misc/maintenance/search_for_data_inconsistencies.pl @@ -128,6 +128,19 @@ use C4::Biblio qw( GetMarcFromKohaField ); } } + my @item_fields_in_marc; + my ( $item_tag, $item_subfield ) = C4::Biblio::GetMarcFromKohaField("items.itemnumber"); + my $search_string = q{ExtractValue(metadata,'count(//datafield[@tag="} . $item_tag . q{"])')>0}; + my $biblio_metadatas_with_item_fields = Koha::Biblio::Metadatas->search( \$search_string ); + if ( $biblio_metadatas_with_item_fields->count ) { + while ( my $biblio_metadata_with_item_fields = $biblio_metadatas_with_item_fields->next ) { + push @item_fields_in_marc, + { + biblionumber => $biblio_metadata_with_item_fields->biblionumber, + }; + } + } + my ( @decoding_errors, @ids_not_in_marc ); my $biblios = Koha::Biblios->search; my ( $biblio_tag, $biblio_subfield ) = C4::Biblio::GetMarcFromKohaField("biblio.biblionumber"); @@ -201,6 +214,19 @@ use C4::Biblio qw( GetMarcFromKohaField ); } new_hint("The bibliographic records must have the biblionumber and biblioitemnumber in MARCXML"); } + if (@item_fields_in_marc) { + new_section("Bibliographic records have item fields in the MARC"); + for my $biblionumber (@item_fields_in_marc) { + new_item( + sprintf( + q{Biblionumber %s has item fields (%s) in the marc record}, + $biblionumber->{biblionumber}, + $item_tag, + ) + ); + } + new_hint("You can fix these by running misc/maintenance/touch_all_biblios.pl"); + } } {