From 53fd3f1f4c80f95dfe9e24d42a558681f526ddcb 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 | 66 +++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/tools/batch_records_ajax.pl b/tools/batch_records_ajax.pl index 1a7130a54a1..8e756a80235 100755 --- a/tools/batch_records_ajax.pl +++ b/tools/batch_records_ajax.pl @@ -35,8 +35,11 @@ use CGI qw ( -utf8 ); use JSON qw( to_json ); use C4::Context; -use C4::Auth qw( check_cookie_auth ); -use C4::ImportBatch qw( GetImportBatch GetImportRecordsRange GetImportRecordMatches ); +use C4::Auth qw( check_cookie_auth ); +use C4::ImportBatch qw( GetImportBatch GetImportRecordsRange GetImportRecordMathes ); +use Koha::Import::Records; +use Koha::Biblios; +use Koha::MetadataRecord::Authority; my $input = CGI->new; @@ -67,48 +70,61 @@ my $records = GetImportRecordsRange( { 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 $match_citation = ''; - if ( $match->{'record_type'} eq 'biblio' ) { + my @matches_arr = (); + if ( $matches->count > 0 ) { + while ( my $match = $matches->next ){ + my $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 ); $match_citation .= $match->{'title'} if defined( $match->{'title'} ); $match_citation .= ' ' . $match->{'author'} if defined( $match->{'author'} ); $match->{'match_citation'} = $match_citation; - } elsif ( $match->{'record_type'} eq 'auth' ) { - if ( defined( $match->{'authorized_heading'} ) ) { + } + 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; $match_citation .= $match->{'authorized_heading'}; $match->{'match_citation'} = $match_citation; } } + push @matches_arr, $match; + } } - push @list, { DT_RowId => $record->{'import_record_id'}, import_record_id => $record->{'import_record_id'}, - citation => $citation, - author => $record->{'author'}, - issn => $record->{'issn'}, - isbn => $record->{'isbn'}, - status => $record->{'status'}, - overlay_status => $record->{'overlay_status'}, - matched => $record->{'matched_biblionumber'} - || $record->{'matched_authid'} - || q{}, + citation => $citation, + author => $record->{'author'}, + issn => $record->{'issn'}, + isbn => $record->{'isbn'}, + status => $record->{'status'}, + overlay_status => $record->{'overlay_status'}, + matched => $record->{'matched_biblionumber'} + || $record->{'matched_authid'} + || q{}, score => scalar @$matches > 0 ? $matches->[0]->{'score'} : 0, - matches => $matches, - 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 - }; + 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 + }; } my $data = { -- 2.39.5