From 43b6c9c3c0751542a7f7daed45fa626484ceb721 Mon Sep 17 00:00:00 2001 From: Eric Garcia Date: Wed, 7 Aug 2024 15:52:11 +0000 Subject: [PATCH] Bug 32055: Change code to use get_import_record_matches To test: 1. Apply patch, restart_all Bibliographic records: 2. Cataloging -> Stage records for import 3. Choose a file with bibliographic records 4. Choose a record matching rule -> Save 5. View batch and notice the table displays the information correctly Authority records: 6. Administration -> Record matching rules -> New record matching rule 7. Add a code, description, and Match Threshold: 1000 8. Match point 1: Search index: local-number Score: 1000 Tag: 001 9. Save 10. Cataloging -> Stage records for import 11. Choose a file with authority records 12. Change Record type to 'Authority' and choose the matching rule you made previously 13. View batch and notice the table displays the information correctly --- tools/batch_records_ajax.pl | 45 ++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/tools/batch_records_ajax.pl b/tools/batch_records_ajax.pl index bcf97e06bd..5d8e30d87c 100755 --- a/tools/batch_records_ajax.pl +++ b/tools/batch_records_ajax.pl @@ -36,7 +36,10 @@ use JSON qw( to_json ); use C4::Context; use C4::Auth qw( check_cookie_auth ); -use C4::ImportBatch qw( GetImportBatch GetImportRecordsRange GetImportRecordMatches ); +use C4::ImportBatch qw( GetImportBatch GetImportRecordsRange ); +use Koha::Import::Records; +use Koha::Biblios; +use Koha::MetadataRecord::Authority; my $input = CGI->new; @@ -66,30 +69,37 @@ my $records = GetImportRecordsRange( $import_batch_id, $offset, $results_per_page, undef, { order_by => $sorting_column, order_by_direction => $sorting_direction } ); my @list = (); + foreach my $record (@$records) { my $citation = $record->{'title'} || $record->{'authorized_heading'}; - - my $matches = GetImportRecordMatches( $record->{'import_record_id'} ); + my $import_record_obj = Koha::Import::Records->find($record->{'import_record_id'}); + my $matches = $import_record_obj->get_import_record_matches(); my $match_id; - if ( scalar @$matches > 0 ) { - foreach my $match (@$matches){ + my @matches_arr = (); + if ( $matches->count > 0 ) { + while ( my $match = $matches->next ){ my $match_citation = ''; - if ( $match->{'record_type'} eq 'biblio' ) { - $match_citation .= $match->{'title'} - if defined( $match->{'title'} ); - $match_citation .= ' ' . $match->{'author'} - if defined( $match->{'author'} ); - $match->{'match_citation'} = $match_citation; + if ( $import_record_obj->record_type eq 'biblio' ) { + my $biblio = Koha::Biblios->find($match->candidate_match_id); + $match = $match->unblessed; + $match->{'record_type'} = 'biblio'; + $match->{'title'} = $biblio->title + if defined( $biblio->title ); + $match->{'author'} = $biblio->author + if defined( $biblio->author ); } - elsif ( $match->{'record_type'} eq 'auth' ) { - if ( defined( $match->{'authorized_heading'} ) ) { - $match_citation .= $match->{'authorized_heading'}; - $match->{'match_citation'} = $match_citation; + elsif ( $import_record_obj->record_type eq 'auth' ) { + my $auth = Koha::MetadataRecord::Authority->get_from_authid($match->candidate_match_id); + $match = $match->unblessed; + $match->{'record_type'} = 'auth'; + if ( defined( $auth->authorized_heading ) ) { + $match->{'authorized_heading'} = $auth->authorized_heading; } } + push @matches_arr, $match; + } } - push @list, { DT_RowId => $record->{'import_record_id'}, @@ -103,8 +113,7 @@ foreach my $record (@$records) { matched => $record->{'matched_biblionumber'} || $record->{'matched_authid'} || q{}, - score => scalar @$matches > 0 ? $matches->[0]->{'score'} : 0, - matches => $matches, + matches => \@matches_arr, diff_url => $match_id ? "/cgi-bin/koha/tools/showdiffmarc.pl?batchid=$import_batch_id&importid=$record->{import_record_id}&id=$match_id&type=$record->{record_type}" : undef }; } -- 2.30.2