Bugzilla – Attachment 126944 Details for
Bug 29325
commit_file.pl error 'Already in a transaction'
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29325: Fix commit_file.pl
Bug-29325-Fix-commitfilepl.patch (text/plain), 3.13 KB, created by
Tomás Cohen Arazi (tcohen)
on 2021-10-26 22:30:34 UTC
(
hide
)
Description:
Bug 29325: Fix commit_file.pl
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2021-10-26 22:30:34 UTC
Size:
3.13 KB
patch
obsolete
>From 597e3f2c756dc30b3a24ccf98fd60d769b91dbcc Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 26 Oct 2021 13:54:15 -0300 >Subject: [PATCH] Bug 29325: Fix commit_file.pl > >This patch fixes the broken commit_file.pl script. > >It doesn't deal with commiting the import from the UI. > >To test: >1. Pick a file for staging: > $ kshell > k$ misc/stage_file.pl --file TestDataImportKoha.mrc >=> SUCCESS: All good >2. Commit! > k$ misc/commit_file.pl --batch-number 1 >=> FAIL: You see >DBIx::Class::Storage::DBI::_exec_txn_begin(): DBI Exception: DBD::mysql::db begin_work failed: Already in a transaction at /kohadevbox/koha/C4/Biblio.pm line 303 >3. Apply this patch >4. Repeat 2 >=> SUCCESS: Commit succeeds >5. Sign off :-D >--- > C4/ImportBatch.pm | 12 +++++++++++- > misc/commit_file.pl | 11 ++++------- > 2 files changed, 15 insertions(+), 8 deletions(-) > >diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm >index 6ae148d6d2..376ce08d94 100644 >--- a/C4/ImportBatch.pm >+++ b/C4/ImportBatch.pm >@@ -569,6 +569,8 @@ sub BatchCommitRecords { > my $batch_id = shift; > my $framework = shift; > >+ my $schema = Koha::Database->schema; >+ > # optional callback to monitor status > # of job > my $progress_interval = 0; >@@ -609,9 +611,17 @@ sub BatchCommitRecords { > my $rec_num = 0; > while (my $rowref = $sth->fetchrow_hashref) { > $record_type = $rowref->{'record_type'}; >+ >+ # first record, begin transaction >+ $schema->txn_begin >+ unless $rec_num; >+ > $rec_num++; >+ > if ($progress_interval and (0 == ($rec_num % $progress_interval))) { >- &$progress_callback($rec_num); >+ # report progress and commit >+ &$progress_callback($rec_num, $schema); >+ $schema->txn_begin; > } > if ($rowref->{'status'} eq 'error' or $rowref->{'status'} eq 'imported') { > $num_ignored++; >diff --git a/misc/commit_file.pl b/misc/commit_file.pl >index efabdfc429..f925ae2298 100755 >--- a/misc/commit_file.pl >+++ b/misc/commit_file.pl >@@ -1,7 +1,7 @@ > #!/usr/bin/perl > >-use strict; >-use warnings; >+use Modern::Perl; >+ > BEGIN { > # find Koha's Perl modules > # test carefully before changing this >@@ -43,8 +43,6 @@ if ($list_batches) { > # in future, probably should tie to a real user account > C4::Context->set_userenv(0, 'batch', 0, 'batch', 'batch', 'batch', 'batch'); > >-my $dbh = C4::Context->dbh; >-$dbh->{AutoCommit} = 0; > if ($batch_number =~ /^\d+$/ and $batch_number > 0) { > my $batch = GetImportBatch($batch_number); > die "$0: import batch $batch_number does not exist in database\n" unless defined $batch; >@@ -57,7 +55,6 @@ if ($batch_number =~ /^\d+$/ and $batch_number > 0) { > unless $batch->{'import_status'} eq "staged" or $batch->{'import_status'} eq "reverted"; > process_batch($batch_number); > } >- $dbh->commit(); > } else { > die "$0: please specify a numeric batch ID\n"; > } >@@ -128,9 +125,9 @@ _SUMMARY_ > > > sub print_progress_and_commit { >- my $recs = shift; >+ my ( $recs, $schema ) = @_; > print "... processed $recs records\n"; >- $dbh->commit(); >+ $schema->txn_commit; > } > > sub print_usage { >-- >2.33.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29325
:
126944
|
127489
|
128033
|
135556
|
135557
|
135558
|
135559
|
135560
|
136390
|
136391
|
136392
|
136393
|
136394
|
136398
|
136399
|
136400
|
136401
|
136402
|
136478
|
136479
|
136480
|
136481
|
136482
|
136496
|
136497
|
136531
|
136803