Bugzilla – Attachment 187460 Details for
Bug 26993
Allow StoreLastBorrower to retain a locally-defined number of previous borrowers
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26993: Use a txn
Bug-26993-Use-a-txn.patch (text/plain), 3.01 KB, created by
Jonathan Druart
on 2025-10-06 11:37:42 UTC
(
hide
)
Description:
Bug 26993: Use a txn
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2025-10-06 11:37:42 UTC
Size:
3.01 KB
patch
obsolete
>From 5fcc3209c0a10ad732b3aeafa3fb79a6fd47ec7e Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 6 Oct 2025 13:28:08 +0200 >Subject: [PATCH] Bug 26993: Use a txn > >--- > Koha/Item.pm | 47 ++++++++++++++++++++++++++++------------------- > 1 file changed, 28 insertions(+), 19 deletions(-) > >diff --git a/Koha/Item.pm b/Koha/Item.pm >index 37dec7fc552..8085a118bd8 100644 >--- a/Koha/Item.pm >+++ b/Koha/Item.pm >@@ -971,28 +971,37 @@ sub last_returned_by { > # Clean up the table by deleting older entries, depending on what StoreLastBorrower is set to > my $max_stored_borrowers = C4::Context->preference('StoreLastBorrower') || 0; > >- # If StoreLastBorrower is 0 or disabled, bail without storing anything. Also delete any remaining rows from the table. >- if ( $max_stored_borrowers == 0 ) { >- $self->_result->last_returned_by->delete_all; >- return $self; >- } >+ my $schema = Koha::Database->new->schema; >+ $schema->txn_do( >+ sub { > >- #Create an entry for last_returned_by >- my $new_record = $self->_result->create_related( >- 'last_returned_by', >- { borrowernumber => $borrowernumber, itemnumber => $self->itemnumber } >- ); >+ # If StoreLastBorrower is 0 or disabled, bail without storing anything. Also delete any remaining rows from the table. >+ if ( $max_stored_borrowers == 0 ) { >+ $self->_result->last_returned_by->delete_all; >+ return $self; >+ } > >- # Get all entries, ordered by newest first >- my @all_entries = >- $self->_result->last_returned_by( {}, { order_by => [ { '-desc' => 'created_on' }, { '-desc' => 'id' } ] } ) >- ->all; >+ # Create an entry for last_returned_by >+ my $new_record = $self->_result->create_related( >+ 'last_returned_by', >+ { borrowernumber => $borrowernumber, itemnumber => $self->itemnumber } >+ ); > >- # If we have more than the limit, delete the excess oldest ones >- if ( scalar(@all_entries) > $max_stored_borrowers ) { >- my @entries_to_delete = splice( @all_entries, $max_stored_borrowers ); >- $_->delete for @entries_to_delete; >- } >+ # Get all entries, ordered by newest first >+ my @all_entries = $self->_result->last_returned_by( >+ {}, >+ { >+ order_by => [ { '-desc' => 'created_on' }, { '-desc' => 'id' } ], >+ } >+ )->all; >+ >+ # If we have more than the limit, delete the excess oldest ones >+ if ( scalar(@all_entries) > $max_stored_borrowers ) { >+ my @entries_to_delete = splice( @all_entries, $max_stored_borrowers ); >+ $_->delete for @entries_to_delete; >+ } >+ } >+ ); > > return $self; > } >-- >2.34.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 26993
:
186773
|
186774
|
186775
|
186776
|
186801
|
186805
|
186806
|
186807
|
186808
|
186809
|
186844
|
186853
|
187311
|
187312
|
187313
|
187314
|
187315
|
187316
|
187459
| 187460 |
187483
|
187484