From d8a20d5edfd83e023471e35e49743d735bfba746 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 19 Jan 2022 14:40:14 +0100 Subject: [PATCH] Bug 29486: Add check in search_for_data_inconsistencies.pl If the MARC record does not contain the correct biblionumber of biblioitemnumber, the script will display the following warning: == Bibliographic records have MARCXML without biblionumber or biblioitemnumber == * Biblionumber 4242 has '1' in 999$c * Biblionumber 4242 has biblioitemnumber '4242' but should be '1' in 999$d => The bibliographic records must have the biblionumber and biblioitemnumber in MARCXML Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize Signed-off-by: Fridolin Somers --- .../search_for_data_inconsistencies.pl | 55 ++++++++++++++++++- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/misc/maintenance/search_for_data_inconsistencies.pl b/misc/maintenance/search_for_data_inconsistencies.pl index 22b0889549..96b15f3264 100755 --- a/misc/maintenance/search_for_data_inconsistencies.pl +++ b/misc/maintenance/search_for_data_inconsistencies.pl @@ -118,17 +118,66 @@ use C4::Biblio qw( GetMarcFromKohaField ); } } - my @decoding_errors; + my ( @decoding_errors, @ids_not_in_marc ); my $biblios = Koha::Biblios->search; + my ( $biblio_tag, $biblio_subfield ) = C4::Biblio::GetMarcFromKohaField( "biblio.biblionumber" ); + my ( $biblioitem_tag, $biblioitem_subfield ) = C4::Biblio::GetMarcFromKohaField( "biblioitems.biblioitemnumber" ); while ( my $biblio = $biblios->next ) { - eval{$biblio->metadata->record;}; - push @decoding_errors, $@ if $@; + my $record = eval{$biblio->metadata->record;}; + if ($@) { + push @decoding_errors, $@; + next; + } + my $biblionumber = $record->subfield($biblio_tag, $biblio_subfield); + my $biblioitemnumber = $record->subfield($biblioitem_tag, $biblioitem_subfield); + if ( $biblionumber != $biblio->biblionumber ) { + push @ids_not_in_marc, + { + biblionumber => $biblio->biblionumber, + biblionumber_in_marc => $biblionumber, + }; + } + if ( $biblioitemnumber != $biblio->biblioitem->biblioitemnumber ) { + push @ids_not_in_marc, + { + biblionumber => $biblio->biblionumber, + biblioitemnumber => $biblio->biblioitem->biblioitemnumber, + biblioitemnumber_in_marc => $biblionumber, + }; + } } if ( @decoding_errors ) { new_section("Bibliographic records have invalid MARCXML"); new_item($_) for @decoding_errors; new_hint("The bibliographic records must have a valid MARCXML or you will face encoding issues or wrong displays"); } + if (@ids_not_in_marc) { + new_section("Bibliographic records have MARCXML without biblionumber or biblioitemnumber"); + for my $id (@ids_not_in_marc) { + if ( exists $id->{biblioitemnumber} ) { + new_item( + sprintf(q{Biblionumber %s has biblioitemnumber '%s' but should be '%s' in %s$%s}, + $id->{biblionumber}, + $id->{biblioitemnumber}, + $id->{biblioitemnumber_in_marc}, + $biblioitem_tag, + $biblioitem_subfield, + ) + ); + } + else { + new_item( + sprintf(q{Biblionumber %s has '%s' in %s$%s}, + $id->{biblionumber}, + $id->{biblionumber_in_marc}, + $biblio_tag, + $biblio_subfield, + ) + ); + } + } + new_hint("The bibliographic records must have the biblionumber and biblioitemnumber in MARCXML"); + } } { -- 2.39.5