From 69c6c05df896edac8f587bc7160822bb744ef3e9 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 13 Sep 2016 15:23:50 +0000 Subject: [PATCH] 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 Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi (cherry picked from commit e5f251a709f3ebfcda57cdf7f32185464a6991d5) Signed-off-by: Jacob O'Mara --- C4/ImportBatch.pm | 24 +++++++++++++++---- Koha/BackgroundJob/MARCImportCommitBatch.pm | 15 ++++++++---- .../en/modules/tools/manage-marc-import.tt | 9 +++++++ misc/commit_file.pl | 7 +++++- misc/cronjobs/import_webservice_batch.pl | 5 +++- svc/import_bib | 5 +++- tools/manage-marc-import.pl | 4 +++- 7 files changed, 55 insertions(+), 14 deletions(-) diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index 905a44aa62..0956ef5f6b 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -509,16 +509,30 @@ sub BatchFindDuplicates { =head2 BatchCommitRecords - 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 ); + 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 => $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 diff --git a/Koha/BackgroundJob/MARCImportCommitBatch.pm b/Koha/BackgroundJob/MARCImportCommitBatch.pm index ac1c47acda..22398aef29 100644 --- a/Koha/BackgroundJob/MARCImportCommitBatch.pm +++ b/Koha/BackgroundJob/MARCImportCommitBatch.pm @@ -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, - sub { my $job_progress = shift; $self->progress( $job_progress )->store }, - { skip_intermediate_commit => 1 }, - ); + 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, + }); my $count = $num_added + $num_updated; if( $count ) { $self->set({ progress => $count, size => $count }); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt index 5b6ad97db6..70eec40898 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt @@ -274,6 +274,15 @@ [% END %] +
+ When replacing records use this framework: + [% END %]
diff --git a/misc/commit_file.pl b/misc/commit_file.pl index d18dda68c4..36a294cc2b 100755 --- a/misc/commit_file.pl +++ b/misc/commit_file.pl @@ -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_; diff --git a/misc/cronjobs/import_webservice_batch.pl b/misc/cronjobs/import_webservice_batch.pl index ae9aa8614c..d5dcdc78f7 100755 --- a/misc/cronjobs/import_webservice_batch.pl +++ b/misc/cronjobs/import_webservice_batch.pl @@ -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; diff --git a/svc/import_bib b/svc/import_bib index f1119b4543..d5727e6589 100755 --- a/svc/import_bib +++ b/svc/import_bib @@ -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 =?"); diff --git a/tools/manage-marc-import.pl b/tools/manage-marc-import.pl index 9c25ec08f2..af94ab2a16 100755 --- a/tools/manage-marc-import.pl +++ b/tools/manage-marc-import.pl @@ -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) { -- 2.39.5