Bug 27245: Replace AutoCommit=0 with txn_begin in bulkmarcimport.pl

To prevent
DBD::mysql::db begin_work failed: Already in a transaction at /usr/share/perl5/DBIx/Class/Storage/DBI.pm line 1588, <GEN45> line 1.

Test plan:
1 - Export more than 100 records
2 - Use bulkmarcimport (with -commit=10) to import them
    perl misc/migration_tools/bulkmarcimport.pl -b -file testbmi.xml -v -m=MARCXML --commit=10
3 - Modify a record to make the import fail (for instance having a too long
lccn)
4 - Use bulkmarcimport (with -commit=10) to import them
    perl misc/migration_tools/bulkmarcimport.pl -b -file testbmi.xml -v -m=MARCXML --commit=10
5 - Notice that the import stops but that the imported record are imported (apart from the last batch of 10)

Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
(cherry picked from commit 4a90c0b647)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Jonathan Druart 2020-12-18 14:41:12 +01:00 committed by Fridolin Somers
parent 48235e4d61
commit f0dadd169b
1 changed files with 7 additions and 5 deletions

View File

@ -252,13 +252,14 @@ else {
# the SQL query to search on isbn
my $sth_isbn = $dbh->prepare("SELECT biblionumber,biblioitemnumber FROM biblioitems WHERE isbn=?");
$dbh->{AutoCommit} = 0;
my $loghandle;
if ($logfile){
$loghandle= IO::File->new($logfile, $writemode) ;
print $loghandle "id;operation;status\n";
}
my $schema = Koha::Database->schema;
$schema->txn_begin;
RECORD: while ( ) {
my $record;
# get records
@ -537,14 +538,15 @@ RECORD: while ( ) {
}
$yamlhash->{$originalid} = $biblionumber if ($yamlfile);
}
$dbh->commit() if (0 == $i % $commitnum);
if ( 0 == $i % $commitnum ) {
$schema->txn_commit;
$schema->txn_begin;
}
}
print $record->as_formatted()."\n" if ($verbose//0)==2;
last if $i == $number;
}
$dbh->commit();
$dbh->{AutoCommit} = 1;
$schema->txn_commit;
if ($fk_off) {
$dbh->do("SET FOREIGN_KEY_CHECKS = 1");