From 194414625d497244c58ac029452f953cc074d1f5 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Mon, 24 Apr 2023 20:05:50 -1000 Subject: [PATCH] Bug 33603: Fix misc/maintenance/search_for_data_inconsistencies.pl when biblio.biblionumber on control field Since bug 29486, misc/maintenance/search_for_data_inconsistencies.pl search for biblio.biblionumber in MARC record with $record->subfield(). This fails when field is a control field (< 10). Idem for biblioitems.biblioitemnumber Test plan : 1.0) On a UNIMARC database (biblio.biblionumber is on 001) 1.1) Run misc/maintenance/search_for_data_inconsistencies.pl => Without patch you get error : Control fields (generally, just tags below 010) do not have subfields, use data() => With patch no error 2.0) On a MARC21 database (biblio.biblionumber is on 999c) 2.1) Run misc/maintenance/search_for_data_inconsistencies.pl => Check you see no error Signed-off-by: David Nind Signed-off-by: Nick Clemens Signed-off-by: Tomas Cohen Arazi (cherry picked from commit cc1695ba96b79d85fe778af1c60b092b149dd449) Signed-off-by: Martin Renvoize (cherry picked from commit 9971011fb9271ee2c8bae9e979c15b51a7fdaad2) Signed-off-by: Lucas Gass (cherry picked from commit 6254b429b6659e38c554d58d784015600634971d) Signed-off-by: Arthur Suzuki --- .../search_for_data_inconsistencies.pl | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/misc/maintenance/search_for_data_inconsistencies.pl b/misc/maintenance/search_for_data_inconsistencies.pl index a7969d6643..c2c94d490c 100755 --- a/misc/maintenance/search_for_data_inconsistencies.pl +++ b/misc/maintenance/search_for_data_inconsistencies.pl @@ -121,8 +121,39 @@ use C4::Biblio qw( GetMarcFromKohaField ); my @decoding_errors; my $biblios = Koha::Biblios->search; 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, $biblioitemnumber ); + if ( $biblio_tag < 10 ) { + my $biblio_control_field = $record->field($biblio_tag); + $biblionumber = $biblio_control_field->data if $biblio_control_field; + } else { + $biblionumber = $record->subfield( $biblio_tag, $biblio_subfield ); + } + if ( $biblioitem_tag < 10 ) { + my $biblioitem_control_field = $record->field($biblioitem_tag); + $biblioitemnumber = $biblioitem_control_field->data if $biblioitem_control_field; + } else { + $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"); -- 2.39.5