Bug 15869: Change framework on overlay

This patch allows for selection of framework to use when overlaying
records - by default it is set to keep the initial framework

To test:
 1 - Create some records using one framework
 2 - Export the records
 3 - Edit the records to add fields not in original framework
 4 - Stage records using a rule that will find matches
 5 - Import
 6 - Note records contain new fields on display, but they are lost on edit
 7 - Apply patch
 8 - Stage records again
 9 - Select a framework that contains the new fields on import
10 - Import records
11 - Note records now use selected framework and are displayed/edited
correctly

Signed-off-by: Andrew Fuerste-Henry <andrewfh@dubcolib.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit e5f251a709)
Signed-off-by: Jacob O'Mara <jacob.omara@ptfs-europe.com>
This commit is contained in:
Nick Clemens 2016-09-13 15:23:50 +00:00 committed by Jacob O'Mara
parent f3ff8211e8
commit 69c6c05df8
7 changed files with 55 additions and 14 deletions

View file

@ -509,16 +509,30 @@ sub BatchFindDuplicates {
=head2 BatchCommitRecords
Takes a hashref containing params for committing the batch - optional parameters 'progress_interval' and
'progress_callback' will define code called every X records.
my ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored) =
BatchCommitRecords( $batch_id, $framework, $progress_interval, $progress_callback, $params );
BatchCommitRecords({
batch_id => $batch_id,
framework => $framework,
overlay_framework => $overlay_framework,
progress_interval => $progress_interval,
progress_callback => $progress_callback,
skip_intermediate_commit => $skip_intermediate_commit
});
Parameter skip_intermediate_commit does what is says.
=cut
sub BatchCommitRecords {
my ( $batch_id, $framework, $progress_interval, $progress_callback, $params ) = @_;
my $params = shift;
my $batch_id = $params->{batch_id};
my $framework = $params->{framework};
my $overlay_framework = $params->{overlay_framework};
my $skip_intermediate_commit = $params->{skip_intermediate_commit};
my $progress_interval = $params->{progress_interval} // 0;
my $progress_callback = $params->{progress_callback};
$progress_interval = 0 unless $progress_interval && $progress_interval =~ /^\d+$/;
$progress_interval = 0 unless ref($progress_callback) eq 'CODE';
@ -646,7 +660,7 @@ sub BatchCommitRecords {
ModBiblio(
$marc_record,
$recordid,
$oldbiblio->frameworkcode,
$overlay_framework // $oldbiblio->frameworkcode,
{
overlay_context => $context,
skip_record_index => 1

View file

@ -59,6 +59,7 @@ sub process {
my $import_batch_id = $args->{import_batch_id};
my $frameworkcode = $args->{frameworkcode};
my $overlay_frameworkcode = $args->{overlay_framework};
my @messages;
my $job_progress = 0;
@ -70,11 +71,15 @@ sub process {
$self->size($size)->store;
( $num_added, $num_updated, $num_items_added,
$num_items_replaced, $num_items_errored, $num_ignored ) =
BatchCommitRecords(
$import_batch_id, $frameworkcode, 50,
BatchCommitRecords({
batch_id => $import_batch_id,
framework => $frameworkcode,
overlay_framework => $overlay_frameworkcode,
progress_interval => 50,
progress_callback =>
sub { my $job_progress = shift; $self->progress( $job_progress )->store },
{ skip_intermediate_commit => 1 },
);
skip_intermediate_commit => 1,
});
my $count = $num_added + $num_updated;
if( $count ) {
$self->set({ progress => $count, size => $count });

View file

@ -274,6 +274,15 @@
<option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option>
[% END %]
</select>
<br/>
When replacing records use this framework:
<select name="overlay_framework" id="overlay_frameworks">
<option value="_USE_ORIG_">Keep original framework</option>
<option value="">Default</option>
[% FOREACH framework IN frameworks %]
<option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option>
[% END %]
</select>
[% END %]
<br />
<input type="submit" class="button" name="mainformsubmit" value="Import this batch into the catalog" />

View file

@ -83,7 +83,12 @@ sub process_batch {
print "... importing MARC records -- please wait\n";
my ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored) =
BatchCommitRecords($import_batch_id, $framework, 100, \&print_progress);
BatchCommitRecords({
batch_id => $import_batch_id,
framework => $framework,
progress_interval => 100,
progress_callback => \&print_progress
});
print "... finished importing MARC records\n";
print <<_SUMMARY_;

View file

@ -46,4 +46,7 @@ EOF
my $batch_ids = GetStagedWebserviceBatches() or exit;
$framework ||= '';
BatchCommitRecords($_, $framework) foreach @$batch_ids;
BatchCommitRecords({
batch_id => $_,
framework => $framework
}) foreach @$batch_ids;

View file

@ -92,7 +92,10 @@ sub import_bib {
my $number_of_matches = BatchFindDuplicates($batch_id, $matcher);
# XXX we are ignoring the result of this;
BatchCommitRecords($batch_id, $framework) if lc($import_mode) eq 'direct';
BatchCommitRecords({
batch_id => $batch_id,
framework => $framework
}) if lc($import_mode) eq 'direct';
my $dbh = C4::Context->dbh();
my $sth = $dbh->prepare("SELECT matched_biblionumber FROM import_biblios WHERE import_record_id =?");

View file

@ -89,11 +89,13 @@ if ($op eq "") {
}
} elsif ($op eq "commit-batch") {
my $frameworkcode = $input->param('framework');
my $overlay_framework = $input->param('overlay_framework');
try {
my $job_id = Koha::BackgroundJob::MARCImportCommitBatch->new->enqueue(
{
import_batch_id => $import_batch_id,
frameworkcode => $frameworkcode
frameworkcode => $frameworkcode,
overlay_framework => $overlay_framework
}
);
if ($job_id) {