From 0568f22fc779b2fc0f470dfd52819236602f0037 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Tue, 6 Sep 2016 13:55:05 +0200 Subject: [PATCH] Bug 17240 - Allow processes that rely on background jobs run in Plack mode - followup Followup If not running in background mode, some calls are made on $job var. --- tools/stage-marc-import.pl | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tools/stage-marc-import.pl b/tools/stage-marc-import.pl index a5f60bd..473355e 100755 --- a/tools/stage-marc-import.pl +++ b/tools/stage-marc-import.pl @@ -98,6 +98,8 @@ if ($completedJobID) { # BatchStageMarcRecords can handle that my $job = undef; + my $progress_interval = 0; + my $progress_callback = undef; my $dbh; if ($runinbackground) { my $job_size = scalar(@$marcrecords); @@ -134,6 +136,11 @@ if ($completedJobID) { # New handle, as we're a child. $dbh = C4::Context->dbh({new => 1}); $dbh->{AutoCommit} = 0; + + if ($runinbackground) { + $progress_interval = 50; + $progress_callback = staging_progress_callback( $job, $dbh ); + } # FIXME branch code my ( $batch_id, $num_valid, $num_items, @import_errors ) = BatchStageMarcRecords( @@ -142,21 +149,24 @@ if ($completedJobID) { $to_marc_plugin, $marc_modification_template, $comments, '', $parse_items, 0, - 50, staging_progress_callback( $job, $dbh ) + $progress_interval, $progress_callback ); my $num_with_matches = 0; my $checked_matches = 0; my $matcher_failed = 0; my $matcher_code = ""; + if ($runinbackground) { + $progress_interval = 50; + $progress_callback = matching_progress_callback( $job, $dbh ); + } if ($matcher_id ne "") { my $matcher = C4::Matcher->fetch($matcher_id); if (defined $matcher) { $checked_matches = 1; $matcher_code = $matcher->code(); $num_with_matches = - BatchFindDuplicates( $batch_id, $matcher, 10, 50, - matching_progress_callback( $job, $dbh ) ); + BatchFindDuplicates( $batch_id, $matcher, 10, $progress_interval, $progress_callback ); SetImportBatchMatcher($batch_id, $matcher_id); SetImportBatchOverlayAction($batch_id, $overlay_action); SetImportBatchNoMatchAction($batch_id, $nomatch_action); @@ -221,6 +231,7 @@ exit 0; sub staging_progress_callback { my $job = shift; + return unless $job; my $dbh = shift; return sub { my $progress = shift; @@ -230,6 +241,7 @@ sub staging_progress_callback { sub matching_progress_callback { my $job = shift; + return unless $job; my $dbh = shift; my $start_progress = $job->progress(); return sub { -- 2.7.4