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 <magnus@libriotech.no>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Nick Clemens 2025-03-21 16:35:15 +00:00 committed by Katrin Fischer
parent 50a68bfa1d
commit f2d40e1c69
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
1 changed files with 26 additions and 0 deletions

View File

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