From c7eb047126275fe9c38149697ee14c3834acabfe Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 26 May 2021 11:42:02 +0000 Subject: [PATCH] Bug 28352: Only check authorised values mapped to DB fields The errors reported seem to be caused by authorised values mapped to MARC fields but not mapped to a koha field. We should additionally make sure to check the Default framework Also, adding comment to indicate we only check records with items, because we do TO test: 1 - In a framework that is not the default map a MARC field to an authorised value, but not a koha field 2 - In SQL, force the kohafield to NULL for the mapping you just make UPDATE marc_subfield_structure SET kohafield = NULL WHERE frameworkcode='BKS' and authorised_value='HINGS_AS' 3 - perl misc/maintenance/search_for_data_inconsistencies.pl 4 - get the following errors: Use of uninitialized value $tmp_kohafield in pattern match (m//) at /kohadevbox/koha/misc/maintenance/search_for_data_inconsistencies.pl line 151. Use of uninitialized value $tmp_kohafield in substitution (s///) at /kohadevbox/koha/misc/maintenance/search_for_data_inconsistencies.pl line 154. Can't call method "get_column" on an undefined value at /kohadevbox/koha/misc/maintenance/search_for_data_inconsistencies.pl line 157. 5 - Apply patch 6 - Repeat 7 - No more errors Signed-off-by: Fridolin Somers Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- .../search_for_data_inconsistencies.pl | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/misc/maintenance/search_for_data_inconsistencies.pl b/misc/maintenance/search_for_data_inconsistencies.pl index a23e7abdc7..22b0889549 100755 --- a/misc/maintenance/search_for_data_inconsistencies.pl +++ b/misc/maintenance/search_for_data_inconsistencies.pl @@ -132,10 +132,21 @@ use C4::Biblio qw( GetMarcFromKohaField ); } { - my $frameworks = Koha::BiblioFrameworks->search; + my @framework_codes = Koha::BiblioFrameworks->search()->get_column('frameworkcode'); + push @framework_codes,""; # The default is not stored in frameworks, we need to force it + my $invalid_av_per_framework = {}; - while ( my $framework = $frameworks->next ) { - my $msss = Koha::MarcSubfieldStructures->search({ frameworkcode => $framework->frameworkcode, authorised_value => { '!=' => [ -and => ( undef, '' ) ]} }); + foreach my $frameworkcode ( @framework_codes ) { + # We are only checking fields that are mapped to DB fields + my $msss = Koha::MarcSubfieldStructures->search({ + frameworkcode => $frameworkcode, + authorised_value => { + '!=' => [ -and => ( undef, '' ) ] + }, + kohafield => { + '!=' => [ -and => ( undef, '' ) ] + } + }); while ( my $mss = $msss->next ) { my $kohafield = $mss->kohafield; my $av = $mss->authorised_value; @@ -143,7 +154,7 @@ use C4::Biblio qw( GetMarcFromKohaField ); my $avs = Koha::AuthorisedValues->search_by_koha_field( { - frameworkcode => $framework->frameworkcode, + frameworkcode => $frameworkcode, kohafield => $kohafield, } ); @@ -154,6 +165,8 @@ use C4::Biblio qw( GetMarcFromKohaField ); $tmp_kohafield =~ s|items|me|; } # replace items.attr with me.attr + + # We are only checking biblios with items my $items = Koha::Items->search( { $tmp_kohafield => @@ -161,12 +174,12 @@ use C4::Biblio qw( GetMarcFromKohaField ); -not_in => [ $avs->get_column('authorised_value'), '' ], '!=' => undef, }, - 'biblio.frameworkcode' => $framework->frameworkcode + 'biblio.frameworkcode' => $frameworkcode }, { join => [ 'biblioitem', 'biblio' ] } ); if ( $items->count ) { - $invalid_av_per_framework->{ $framework->frameworkcode }->{$av} = + $invalid_av_per_framework->{ $frameworkcode }->{$av} = { items => $items, kohafield => $kohafield }; } } -- 2.39.5