From efb310cda043a9fad49c672630ef7ac533c89210 Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Thu, 20 Aug 2026 12:08:20 +0200 Subject: [PATCH] Bug 43346: MarkIssueReturned with no userenv Since it is not clear what checkin_library signifies when marking an issue on a lost item as returned we might as well fallback on setting it to the issuing library when there is no userenv. Test plan * Run the unit test t/db_dependent/Koha/Account/Line.t Signed-off-by: David Nind Signed-off-by: Jason Robb Signed-off-by: Pedro Amorim --- C4/Circulation.pm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 12bafdf51c..fd64f5bf3f 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3002,7 +3002,7 @@ sub MarkIssueReturned { my $schema = Koha::Database->schema; # FIXME Improve the return value and handle it from callers - $schema->txn_do( + my $rv = $schema->txn_do( sub { my $patron = Koha::Patrons->find($borrowernumber); @@ -3014,7 +3014,9 @@ sub MarkIssueReturned { $issue->returndate( \'NOW()' )->store->discard_changes; # update and refetch } - $issue->checkin_library( C4::Context->userenv->{'branch'} ); + my $checkin_library = defined C4::Context->userenv + && exists C4::Context->userenv->{'branch'} ? C4::Context->userenv->{'branch'} : $issue->branchcode; + $issue->checkin_library($checkin_library); # Create the old_issues entry my $old_checkout = Koha::Old::Checkout->new( $issue->unblessed )->store;