Koha/tools/batch_records_ajax.pl
Nick Clemens 48ae97e361 Bug 22785: Allow option to choose which record match is applied during import
This patchset adds the display of all matches found during import to the import management screen

A staff member with the permission to manage batches will be able to select for any individual record which match, or none, should be used during import

To test:
1 - Import a batch of records or export existing records from your catalog
2 - Import the file (again) and select a matching rule that will find matches
3 - Note that you now have radio buttons allowing you to select a record, or none
4 - Test scenarios:
    I - When 'Action if matching record found' is 'Ignore'
        a - Imported record ignored if match is selected
        b - 'Action if no match found' followed if no match is selected (Ignore matches)
    II - When 'Action if matching record found' is 'Replace'
        a - The chosen record is the one overlayed (you can edit the chosen record before importing to confirm)
        b - 'Action if no match found' followed if no match is selected (Ignore matches)
    III - When 'Action if matching record found' is 'Add incoming record'
        a - Record is added regardless of matches
5 - Confirm 'Diff' 'View' links work as expected
6 - Confirm that after records are imported the radio buttons to choose are disabled

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>

Bug 22785: API files

Signed-off-by: Ben Daeuber <bdaeuber@cityoffargo.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
2022-05-03 11:19:50 -10:00

117 lines
4.1 KiB
Perl
Executable file

#!/usr/bin/perl
# Copyright 2013 ByWater Solutions
# Based on circ/ysearch.pl: Copyright 2007 Tamil s.a.r.l.
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
=head1 NAME
batch_records_ajax.pl - A script for searching batch imported records via ajax
=head1 SYNOPSIS
This script is to be used as a data source for DataTables that load and display
the records from an import batch.
=cut
use Modern::Perl;
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 );
my $input = CGI->new;
my @sort_columns =
qw/import_record_id title status overlay_status overlay_status/;
my $import_batch_id = $input->param('import_batch_id');
my $offset = $input->param('iDisplayStart');
my $results_per_page = $input->param('iDisplayLength');
my $sorting_column = $sort_columns[ $input->param('iSortCol_0') // 0 ];
my $sorting_direction = $input->param('sSortDir_0');
$results_per_page = undef if $results_per_page && $results_per_page == -1;
binmode STDOUT, ":encoding(UTF-8)";
print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
my ( $auth_status ) =
check_cookie_auth( $input->cookie('CGISESSID'), { tools => 'manage_staged_marc' } );
if ( $auth_status ne "ok" ) {
exit 0;
}
my $batch = GetImportBatch($import_batch_id);
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 $match_id;
if ( scalar @$matches > 0 ) {
foreach my $match (@$matches){
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;
}
elsif ( $match->{'record_type'} eq 'auth' ) {
if ( defined( $match->{'authorized_heading'} ) ) {
$match_citation .= $match->{'authorized_heading'};
$match->{'match_citation'} = $match_citation;
}
}
}
}
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{},
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
};
}
my $data;
$data->{'iTotalRecords'} = $batch->{'num_records'};
$data->{'iTotalDisplayRecords'} = $batch->{'num_records'};
$data->{'sEcho'} = $input->param('sEcho') || undef;
$data->{'aaData'} = \@list;
print to_json($data);