From d533f2bbffe11da7a6c52af4fb93fce453ee501f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 26 Mar 2026 10:34:28 +0100 Subject: [PATCH] Bug 42185: Remove C4::Context::_new_dbh This looks trivial at first, but it's not, because of forking and the comment in C4::Context I don't think the comment makes sense, we need to retrieve a new dbh, and so passing the 'new' parameters to C4::Context->dbh should do the same. Test plan: Try rebuild_zebra.pl and confirm there is no error % perl misc/migration_tools/rebuild_zebra.pl --processes 2 -b Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Thomas Klausner Signed-off-by: Lucas Gass --- C4/Context.pm | 9 --------- misc/migration_tools/rebuild_zebra.pl | 4 ++-- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/C4/Context.pm b/C4/Context.pm index 9e48a499b9..25c8832d55 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -613,15 +613,6 @@ sub _new_Zconn { return $Zconn; } -# _new_dbh -# Internal helper function (not a method!). This creates a new -# database connection from the data given in the current context, and -# returns it. -sub _new_dbh { - - Koha::Database->schema( { new => 1 } )->storage->dbh; -} - =head2 dbh $dbh = C4::Context->dbh; diff --git a/misc/migration_tools/rebuild_zebra.pl b/misc/migration_tools/rebuild_zebra.pl index a4a9410ee5..2603f4820f 100755 --- a/misc/migration_tools/rebuild_zebra.pl +++ b/misc/migration_tools/rebuild_zebra.pl @@ -524,7 +524,7 @@ sub select_all_authorities { $strsth .= qq{ LIMIT $offset,$length } if ( $length && $offset ); # If we are forking, we use a new db handle to prevent a potential deadlock - my $sth = $forks ? C4::Context::_new_dbh->prepare($strsth) : $dbh->prepare($strsth); + my $sth = $forks ? C4::Context->dbh( { new => 1 } )->prepare($strsth) : $dbh->prepare($strsth); $sth->execute(); return $sth; } @@ -538,7 +538,7 @@ sub select_all_biblios { $strsth .= qq{ LIMIT $offset,$length } if ($offset); # If we are forking, we use a new db handle to prevent a potential deadlock - my $sth = $forks ? C4::Context::_new_dbh->prepare($strsth) : $dbh->prepare($strsth); + my $sth = $forks ? C4::Context->dbh( { new => 1 } )->prepare($strsth) : $dbh->prepare($strsth); $sth->execute(); return $sth; }