From 67bd6156405f7fa11dcc2767b618bc63d40567f0 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Thu, 11 Mar 2021 11:46:46 +0100 Subject: [PATCH] Bug 21818: Replace AutoCommit flag with DBIx transaction in stage-marc-import.pl Like it was done in Bug 18806. Test plan : Use stage-marc-import.pl with and without patch, with a matcher to find duplicates Signed-off-by: Katrin Fischer --- tools/stage-marc-import.pl | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tools/stage-marc-import.pl b/tools/stage-marc-import.pl index 97767bfa1b..9f285efe87 100755 --- a/tools/stage-marc-import.pl +++ b/tools/stage-marc-import.pl @@ -106,7 +106,6 @@ if ($completedJobID) { # BatchStageMarcRecords can handle that my $job = undef; - my $dbh; if ($runinbackground) { my $job_size = scalar(@$marcrecords); # if we're matching, job size is doubled @@ -139,9 +138,9 @@ if ($completedJobID) { } - # New handle, as we're a child. - $dbh = C4::Context->dbh({new => 1}); - $dbh->{AutoCommit} = 0; + my $schema = Koha::Database->new->schema; + $schema->storage->txn_begin; + # FIXME branch code my ( $batch_id, $num_valid, $num_items, @import_errors ) = BatchStageMarcRecords( @@ -150,7 +149,7 @@ if ($completedJobID) { $marc_modification_template, $comments, '', $parse_items, 0, - 50, staging_progress_callback( $job, $dbh ) + 50, staging_progress_callback( $job ) ); if($profile_id) { @@ -169,17 +168,18 @@ if ($completedJobID) { $matcher_code = $matcher->code(); $num_with_matches = BatchFindDuplicates( $batch_id, $matcher, 10, 50, - matching_progress_callback( $job, $dbh ) ); + matching_progress_callback($job) ); SetImportBatchMatcher($batch_id, $matcher_id); SetImportBatchOverlayAction($batch_id, $overlay_action); SetImportBatchNoMatchAction($batch_id, $nomatch_action); SetImportBatchItemAction($batch_id, $item_action); - $dbh->commit(); + $schema->storage->txn_commit; } else { $matcher_failed = 1; + $schema->storage->txn_rollback; } } else { - $dbh->commit(); + $schema->storage->txn_commit; } my $results = { @@ -239,7 +239,6 @@ exit 0; sub staging_progress_callback { my $job = shift; - my $dbh = shift; return sub { my $progress = shift; $job->progress($progress); @@ -248,7 +247,6 @@ sub staging_progress_callback { sub matching_progress_callback { my $job = shift; - my $dbh = shift; my $start_progress = $job->progress(); return sub { my $progress = shift; -- 2.11.0