Bugzilla – Attachment 185195 Details for
Bug 32776
Choose to convert oldest reserve or all possible reserves to recalls
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 32776: (follow-up) Fixing more terminology and tidy up
Bug-32776-follow-up-Fixing-more-terminology-and-ti.patch (text/plain), 10.74 KB, created by
Aleisha Amohia
on 2025-08-07 05:10:03 UTC
(
hide
)
Description:
Bug 32776: (follow-up) Fixing more terminology and tidy up
Filename:
MIME Type:
Creator:
Aleisha Amohia
Created:
2025-08-07 05:10:03 UTC
Size:
10.74 KB
patch
obsolete
>From a706f5ea35f4e3f750673b76d3b6134ddd295dad Mon Sep 17 00:00:00 2001 >From: Aleisha Amohia <aleishaamohia@hotmail.com> >Date: Thu, 7 Aug 2025 05:06:05 +0000 >Subject: [PATCH] Bug 32776: (follow-up) Fixing more terminology and tidy up > >--- > ...d_ConvertSelectedHoldsToRecalls_syspref.pl | 10 +- > .../recalls/convert_holds_to_recalls.pl | 106 ++++++++++-------- > 2 files changed, 68 insertions(+), 48 deletions(-) > >diff --git a/installer/data/mysql/atomicupdate/bug_32776_-_add_ConvertSelectedHoldsToRecalls_syspref.pl b/installer/data/mysql/atomicupdate/bug_32776_-_add_ConvertSelectedHoldsToRecalls_syspref.pl >index a1cb83c122d..efd42bcb1d4 100755 >--- a/installer/data/mysql/atomicupdate/bug_32776_-_add_ConvertSelectedHoldsToRecalls_syspref.pl >+++ b/installer/data/mysql/atomicupdate/bug_32776_-_add_ConvertSelectedHoldsToRecalls_syspref.pl >@@ -1,13 +1,15 @@ > use Modern::Perl; > > return { >- bug_number => "32776", >+ bug_number => "32776", > description => "Convert selected reserves to recalls", >- up => sub { >+ up => sub { > my ($args) = @_; >- my ($dbh, $out) = @$args{qw(dbh out)}; >+ my ( $dbh, $out ) = @$args{qw(dbh out)}; > >- $dbh->do(q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('ConvertSelectedHoldsToRecalls', 'oldest', 'oldest|recallable', 'Choose whether the convert_reserves_to_recalls.pl cronjob should convert only the oldest reserve on the record to a recall, or one reserve for each item available to be recalled', 'Choice') }); >+ $dbh->do( >+ q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('ConvertSelectedHoldsToRecalls', 'oldest', 'oldest|recallable', 'Choose whether the convert_reserves_to_recalls.pl cronjob should convert only the oldest reserve on the record to a recall, or one reserve for each item available to be recalled', 'Choice') } >+ ); > > say $out "Added system preference 'ConvertSelectedHoldsToRecalls'"; > }, >diff --git a/misc/cronjobs/recalls/convert_holds_to_recalls.pl b/misc/cronjobs/recalls/convert_holds_to_recalls.pl >index 961595b4da4..5b8121c88a2 100755 >--- a/misc/cronjobs/recalls/convert_holds_to_recalls.pl >+++ b/misc/cronjobs/recalls/convert_holds_to_recalls.pl >@@ -46,11 +46,11 @@ This script converts holds to recalls when a record has a set minimum number of > > If a record is found to have the specified minimum number of holds, the script will find the oldest hold and convert it to a recall, as long as it would be a legal recall. > >-This script uses the ConvertedSelectedHoldsToRecalls system preference. >+This script uses the ConvertSelectedHoldsToRecalls system preference. > >-When ConvertedSelectedHoldsToRecalls is set to 'oldest', this script will only convert the single oldest hold. Once converted, the script will move on to the next record, it will not continue to convert holds on this record. >+When ConvertSelectedHoldsToRecalls is set to 'oldest', this script will only convert the single oldest hold. Once converted, the script will move on to the next record, it will not continue to convert holds on this record. > >-When ConvertedSelectedHoldsToRecalls is set to 'recallable', this script will convert reserves one-by-one, oldest first, until all recallable items have been recalled. >+When ConvertSelectedHoldsToRecalls is set to 'recallable', this script will convert reserves one-by-one, oldest first, until all recallable items have been recalled. > > Options: > -v verbose >@@ -76,46 +76,53 @@ my $min = 5; > my $verbose; > > GetOptions( >- 'min|m=i' => \$min, >+ 'min|m=i' => \$min, > 'verbose|v' => \$verbose > ) or pod2usage(1); > > # get holds where there is more than $min holds on one biblio >-my @bib_holds = Koha::Holds->search({}, { >- select => [ >- 'biblionumber', >- { count => 'biblionumber', -as => 'bibcount' } >- ], >- group_by => 'biblionumber', >- having => { 'bibcount' => { '>=', $min } }, >-})->as_list; >+my @bib_holds = Koha::Holds->search( >+ {}, >+ { >+ select => [ >+ 'biblionumber', >+ { count => 'biblionumber', -as => 'bibcount' } >+ ], >+ group_by => 'biblionumber', >+ having => { 'bibcount' => { '>=', $min } }, >+ } >+)->as_list; > > my $count = 0; >-foreach my $bib ( @bib_holds ) { >+foreach my $bib (@bib_holds) { > $bib = $bib->unblessed; >+ > # If there are $min or more holds on the same record, we can begin converting holds > if ( $bib->{bibcount} >= $min ) { > > # Get all holds on this biblio >- my @holds = Koha::Holds->search({ biblionumber => $bib->{biblionumber}, found => undef }, { order_by => { -asc => 'reservedate' } })->as_list; >+ my @holds = Koha::Holds->search( >+ { biblionumber => $bib->{biblionumber}, found => undef }, >+ { order_by => { -asc => 'reservedate' } } >+ )->as_list; > >- if ( C4::Context->preference('ConvertedSelectedHoldsToRecalls') eq 'oldest' ) { >+ if ( C4::Context->preference('ConvertSelectedHoldsToRecalls') eq 'oldest' ) { > >- my $hold_to_convert = $holds[0]; >- my $itemnumber_to_allocate = can_convert( $hold_to_convert ); >- if ( $itemnumber_to_allocate ) { >- my $item_to_allocate = Koha::Items->find( $itemnumber_to_allocate ); >+ my $hold_to_convert = $holds[0]; >+ my $itemnumber_to_allocate = can_convert($hold_to_convert); >+ if ($itemnumber_to_allocate) { >+ my $item_to_allocate = Koha::Items->find($itemnumber_to_allocate); > do_convert( $hold_to_convert, $item_to_allocate ); > report( $hold_to_convert, ++$count ); > } > >- } elsif ( C4::Context->preference('ConvertedSelectedHoldsToRecalls') eq 'recallable' ) { >+ } elsif ( C4::Context->preference('ConvertSelectedHoldsToRecalls') eq 'recallable' ) { > > my $this_record_holds_converted = 0; > >- my @items = Koha::Items->search({ biblionumber => $bib->{biblionumber} })->as_list; >- foreach my $item ( @items ) { >- my $hold_to_convert = $holds[ $this_record_holds_converted ]; >+ my @items = Koha::Items->search( { biblionumber => $bib->{biblionumber} } )->as_list; >+ foreach my $item (@items) { >+ my $hold_to_convert = $holds[$this_record_holds_converted]; > > if ( !$hold_to_convert ) { > last; >@@ -123,8 +130,9 @@ foreach my $bib ( @bib_holds ) { > > my $itemnumber_to_allocate = can_convert( $hold_to_convert, $item ); > >- if ( $itemnumber_to_allocate ) { >- my $item_to_allocate = $itemnumber_to_allocate == $item->id ? $item : Koha::Items->find( $itemnumber_to_allocate ); >+ if ($itemnumber_to_allocate) { >+ my $item_to_allocate = >+ $itemnumber_to_allocate == $item->id ? $item : Koha::Items->find($itemnumber_to_allocate); > do_convert( $hold_to_convert, $item_to_allocate ); > report( $hold_to_convert, ++$count ); > $this_record_holds_converted++; >@@ -144,32 +152,40 @@ sub can_convert { > if ( $hold->item_level_hold ) { > > if ( $item and $item->id == $hold->itemnumber ) { >+ > # item-level reserve, on this specific item >- if ( $item->can_be_recalled({ patron => $patron, hold_convert => 1 }) ) { >+ if ( $item->can_be_recalled( { patron => $patron, hold_convert => 1 } ) ) { > return $item->id; > } > } else { >+ > # item-level reserve but not on this item > # so check if intended item can be allocated for the recall > $item = Koha::Items->find( $hold->itemnumber ); >- if ( $item and $item->can_be_recalled({ patron => $patron, hold_convert => 1 }) ) { >+ if ( $item and $item->can_be_recalled( { patron => $patron, hold_convert => 1 } ) ) { > return $item->id; > } > } > > } else { >+ > # bib-level reserve > >- if ( $item and $item->can_be_recalled({ patron => $patron, hold_convert => 1 }) and Koha::Recalls->filter_by_current->search({ item_id => $item->id })->count < 1 ) { >- # this item may be able to fill the recall >- return $item->id; >+ if ( C4::Context->preference('ConvertSelectedHoldsToRecalls') eq 'oldest' ) { >+ if ( $item >+ and $item->can_be_recalled( { patron => $patron, hold_convert => 1 } ) >+ and Koha::Recalls->filter_by_current->search( { item_id => $item->id } )->count < 1 ) >+ { >+ # this item may be able to fill the recall >+ return $item->id; >+ } > } > > # don't have a specific item to allocate for this recall > # so get an eligible item that's not already recalled > foreach my $i ( $biblio->items->as_list ) { >- if ( Koha::Recalls->filter_by_current->search({ item_id => $i->id })->count < 1 ) { >- if ( $i and $i->can_be_recalled({ patron => $patron, hold_convert => 1 }) ) { >+ if ( Koha::Recalls->filter_by_current->search( { item_id => $i->id } )->count < 1 ) { >+ if ( $i and $i->can_be_recalled( { patron => $patron, hold_convert => 1 } ) ) { > return $i->id; > } > } >@@ -189,23 +205,25 @@ sub do_convert { > my $patron = Koha::Patrons->find( $hold->borrowernumber ); > my $biblio = Koha::Biblios->find( $hold->biblionumber ); > >- my ( $recall, $due_interval, $due_date ) = Koha::Recalls->add_recall({ >- patron => $patron, >- biblio => $biblio, >- branchcode => $hold->branchcode, >- item => $item, >- expirationdate => $hold->patron_expiration_date ? $hold->patron_expiration_date : $hold->expirationdate, >- interface => 'commandline', >- }); >- $hold->cancel({ cancellation_reason => 'RECALLED' }); >+ my ( $recall, $due_interval, $due_date ) = Koha::Recalls->add_recall( >+ { >+ patron => $patron, >+ biblio => $biblio, >+ branchcode => $hold->branchcode, >+ item => $item, >+ expirationdate => $hold->patron_expiration_date ? $hold->patron_expiration_date : $hold->expirationdate, >+ interface => 'commandline', >+ } >+ ); >+ $hold->cancel( { cancellation_reason => 'RECALLED' } ); > } > > sub report { >- my $hold = shift; >+ my $hold = shift; > my $count = shift; > >- if ( $verbose ) { >- my $hold_id = $hold->reserve_id; >+ if ($verbose) { >+ my $hold_id = $hold->reserve_id; > my $biblionumber = $hold->biblionumber; > print "$count. Hold converted to recall (reserve_id: $hold_id, biblionumber: $biblionumber).\n"; > } >-- >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 32776
:
145987
|
145988
|
157004
|
157005
|
157006
|
157007
|
157178
|
157966
|
158015
|
159125
|
159126
|
159127
|
185191
|
185192
|
185193
|
185194
| 185195