Bugzilla – Attachment 186776 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: Implement changes
Bug-26993-Implement-changes.patch (text/plain), 7.37 KB, created by
Lucas Gass (lukeg)
on 2025-09-22 21:45:15 UTC
(
hide
)
Description:
Bug 26993: Implement changes
Filename:
MIME Type:
Creator:
Lucas Gass (lukeg)
Created:
2025-09-22 21:45:15 UTC
Size:
7.37 KB
patch
obsolete
>From 93fe84c855ee5290f714073b4749a6b3f4465445 Mon Sep 17 00:00:00 2001 >From: Lucas Gass <lucas@bywatersolutions.com> >Date: Mon, 22 Sep 2025 21:41:54 +0000 >Subject: [PATCH] Bug 26993: Implement changes > >Test plan: > >1. APPLY patch, restart_all, updatedatabase >2. Search for the StoreLastBorrower system preference, it should now allow you to enter a number of borrowers to store >3. Set the pref to 3. >4. Check an item out to any patron. Then immediately check it back in. >5. On catalogue/moredetail.pl?biblionumber=X ( where X is you biblionumber ) you should see a "Last returned by:" entry with the correct cardnumber for the borrower. >7. Confirm this is right in the database with: SELECT * FROM items_last_borrower where itemnumber = X; ( Where X is your itemnumber ) >8. Repeat step 4 to a different borrower. >9. Repeat steps 5 and 6. You should see 2 cardnumbers of each of the borrowers on catalogue/moredetail.pl?biblionumber=X >10. Repeat step 4 with another new borrower. >11. Repeat steps 5 and 6. You should see 3 cardnumbers of each of the borrowers on catalogue/moredetail.pl?biblionumber=X >12. Choose a different item and repeat steps 4 - 11 for this item. >13. Now set the StoreLastBorrower preference to 0. >14. Using the original item from step 4, check something out to a patron and immediately check it back in. >15. catalogue/moredetail.pl?biblionumber=X should NOT have an entry for "Last returned by:" >16. Check the database, all entries for the itemnumber from step 14 should be deleted. >--- > C4/Circulation.pm | 6 +- > Koha/Item.pm | 58 ++++++++++++++++++- > .../prog/en/modules/catalogue/moredetail.tt | 19 ++++-- > 3 files changed, 71 insertions(+), 12 deletions(-) > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index e03a5e27fb7..4dc447ddf15 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -2918,10 +2918,8 @@ sub MarkIssueReturned { > } > ); > >- if ( C4::Context->preference('StoreLastBorrower') ) { >- my $item = Koha::Items->find($itemnumber); >- $item->last_returned_by( $patron->borrowernumber )->store; >- } >+ my $item = Koha::Items->find($itemnumber); >+ $item->last_returned_by( $patron->borrowernumber )->store; > > # Possibly remove any OVERDUES related debarment > my $overdue_restrictions = $patron->restrictions->search( { type => 'OVERDUES' } ); >diff --git a/Koha/Item.pm b/Koha/Item.pm >index c675d0638e4..6781c46dbeb 100644 >--- a/Koha/Item.pm >+++ b/Koha/Item.pm >@@ -927,6 +927,28 @@ sub get_transfers { > return Koha::Item::Transfers->_new_from_dbic($transfers_rs); > } > >+=head3 last_returned_by_all >+ >+Returns all patrons who have returned this item, ordered by most recent first. >+ >+=cut >+ >+sub last_returned_by_all { >+ my ($self) = @_; >+ >+ my $max_stored_borrowers = C4::Context->preference('StoreLastBorrower') || 0; >+ >+ my @borrowers = $self->_result->last_returned_by( >+ {}, >+ { >+ order_by => { -desc => 'created_on' }, >+ rows => $max_stored_borrowers, >+ } >+ ); >+ >+ return map { Koha::Patron->_new_from_dbic( $_->borrowernumber ) } @borrowers; >+} >+ > =head3 last_returned_by > > Gets and sets the last patron to return an item. >@@ -941,13 +963,45 @@ my $patron = $item->last_returned_by(); > > sub last_returned_by { > my ( $self, $borrowernumber ) = @_; >+ > if ($borrowernumber) { >- $self->_result->update_or_create_related( >+ >+ # 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; >+ } >+ >+ #Create an entry for last_returned_by >+ my $new_record = $self->_result->create_related( > 'last_returned_by', > { borrowernumber => $borrowernumber, itemnumber => $self->itemnumber } > ); >+ >+ # Get all records, ordered by newest first >+ my @all_records = $self->_result->last_returned_by( {}, { order_by => { -desc => 'created_on' } } )->all; >+ >+ # If we have more than the limit, delete the excess oldest ones >+ if ( scalar(@all_records) > $max_stored_borrowers ) { >+ my @entries_to_delete = splice( @all_records, $max_stored_borrowers ); >+ $_->delete for @entries_to_delete; >+ } >+ >+ return $self; > } >- my $rs = $self->_result->last_returned_by; >+ >+ # Return the most recent borrower >+ my $rs = $self->_result->last_returned_by( >+ {}, >+ { >+ order_by => { -desc => 'created_on' }, >+ rows => 1 >+ } >+ )->first; >+ > return unless $rs; > return Koha::Patron->_new_from_dbic( $rs->borrowernumber ); > } >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt >index 93faa13bec9..655f0244a8b 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt >@@ -493,13 +493,20 @@ > <span class="label">Last borrowed:</span> > [% IF (ITEM_DAT.datelastborrowed ) %][% ITEM_DAT.datelastborrowed | $KohaDates %][% END %] > </li> >- [% IF Koha.Preference('StoreLastBorrower') && ITEM_DAT.object.last_returned_by %] >- [% SET last_returned_by = ITEM_DAT.object.last_returned_by.cardnumber || ITEM_DAT.object.last_returned_by.borrowernumber %] >- <li> >- <span class="label">Last returned by:</span> >- <a href="/cgi-bin/koha/circ/circulation.pl?borrowernumber=[% ITEM_DAT.object.last_returned_by.borrowernumber | uri %]">[% last_returned_by | html %]</a> >- </li> >+ >+ [% IF Koha.Preference('StoreLastBorrower') && Koha.Preference('StoreLastBorrower') > 0 %] >+ [% SET all_borrowers = ITEM_DAT.object.last_returned_by_all %] >+ [% IF all_borrowers.size > 0 %] >+ <li> >+ <span class="label">Last returned by:</span> >+ [% FOREACH patron IN all_borrowers %] >+ [% SET returned_by = patron.cardnumber || patron.borrowernumber %] >+ <a href="/cgi-bin/koha/circ/circulation.pl?borrowernumber=[% patron.borrowernumber | uri %]">[% returned_by | html %]</a>[% UNLESS loop.last %],[% END %] >+ [% END %] >+ </li> >+ [% END %] > [% END %] >+ > [% FOR i IN ITEM_DAT.old_issues %] > [% SET b = i.patron %] > <li class="previous_borrowers"> >-- >2.39.5
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