@@ -, +, @@ 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 --- C4/ImportBatch.pm | 32 +++++++++++++--------- .../prog/en/modules/tools/manage-marc-import.tt | 9 ++++++ misc/commit_file.pl | 7 ++++- misc/cronjobs/import_webservice_batch.pl | 6 +++- svc/import_bib | 5 +++- tools/manage-marc-import.pl | 16 ++++++++--- 6 files changed, 55 insertions(+), 20 deletions(-) --- a/C4/ImportBatch.pm +++ a/C4/ImportBatch.pm @@ -550,26 +550,32 @@ 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); + BatchCommitRecords({ + batch_id => $batch_id, + framework => $framework, + overlay_framework => $overlay_framework, + progress_interval => $progress_interval, + progress_callback => $progress_callback + }); =cut sub BatchCommitRecords { - my $batch_id = shift; - my $framework = shift; + my $params = shift; + my $batch_id = $params->{batch_id}; + my $framework = $params->{framework}; + my $overlay_framework = $params->{overlay_framework}; # optional callback to monitor status # of job - my $progress_interval = 0; - my $progress_callback = undef; - if ($#_ == 1) { - $progress_interval = shift; - $progress_callback = shift; - $progress_interval = 0 unless $progress_interval =~ /^\d+$/ and $progress_interval > 0; - $progress_interval = 0 unless 'CODE' eq ref $progress_callback; - } + my $progress_interval = $params->{progress_interval} // 0; + my $progress_callback = $params->{progress_callback}; + $progress_interval = 0 unless $progress_interval =~ /^\d+$/ and $progress_interval > 0; + $progress_interval = 0 unless 'CODE' eq ref $progress_callback; my $record_type; my $num_added = 0; @@ -666,7 +672,7 @@ sub BatchCommitRecords { } $oldxml = $old_marc->as_xml($marc_type); - ModBiblio($marc_record, $recordid, $oldbiblio->frameworkcode); + ModBiblio($marc_record, $recordid, $overlay_framework // $oldbiblio->frameworkcode); $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; if ($item_result eq 'create_new' || $item_result eq 'replace') { --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt @@ -211,6 +211,15 @@ [% END %] +
+ When replacing records use this framework: + [% END %]
--- a/misc/commit_file.pl +++ a/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, '', 100, \&print_progress_and_commit); + BatchCommitRecords({ + batch_id => $import_batch_id, + framework => '', + progress_interval => 100, + progress_callback => \&print_progress_and_commit + }); print "... finished importing MARC records\n"; print <<_SUMMARY_; --- a/misc/cronjobs/import_webservice_batch.pl +++ a/misc/cronjobs/import_webservice_batch.pl @@ -54,4 +54,8 @@ EOF my $batch_ids = GetStagedWebserviceBatches() or exit; $framework ||= ''; -BatchCommitRecords($_, $framework) foreach @$batch_ids; +BatchCommitRecords({ + batch_id => $_, + framework => $framework +}) foreach @$batch_ids; + --- a/svc/import_bib +++ a/svc/import_bib @@ -88,7 +88,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 =?"); --- a/tools/manage-marc-import.pl +++ a/tools/manage-marc-import.pl @@ -99,7 +99,8 @@ if ($op eq "") { add_saved_job_results_to_template($template, $completedJobID); } else { my $framework = $input->param('framework'); - commit_batch($template, $import_batch_id, $framework); + my $overlay_framework = $input->param('overlay_framework'); + commit_batch($template, $import_batch_id, $framework, $overlay_framework); } import_records_list($template, $import_batch_id, $offset, $results_per_page); } elsif ($op eq "revert-batch") { @@ -230,7 +231,7 @@ sub import_batches_list { } sub commit_batch { - my ($template, $import_batch_id, $framework) = @_; + my ($template, $import_batch_id, $framework, $overlay_framework) = @_; my $job = undef; my ( $num_added, $num_updated, $num_items_added, @@ -243,12 +244,19 @@ sub commit_batch { $job = put_in_background($import_batch_id); $callback = progress_callback( $job, $dbh ); } + my $params = { + batch_id => $import_batch_id, + framework => $framework, + progress_interval => 50, + progress_callback => $callback + }; + $params->{overlay_framework} = $overlay_framework unless $overlay_framework eq '_USE_ORIG_'; + ( $num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored ) - = BatchCommitRecords( $import_batch_id, $framework, 50, - $callback ); + = BatchCommitRecords($params); } ); --