Bugzilla – Attachment 181233 Details for
Bug 31698
Add ability to move a hold to a new bibliographic record/item
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31698: Combine item and record level subroutines
Bug-31698-Combine-item-and-record-level-subroutine.patch (text/plain), 7.73 KB, created by
Lucas Gass (lukeg)
on 2025-04-21 22:02:34 UTC
(
hide
)
Description:
Bug 31698: Combine item and record level subroutines
Filename:
MIME Type:
Creator:
Lucas Gass (lukeg)
Created:
2025-04-21 22:02:34 UTC
Size:
7.73 KB
patch
obsolete
>From 02f13537f6096cc88324ff3491cf828acf7f97f9 Mon Sep 17 00:00:00 2001 >From: Lucas Gass <lucas@bywatersolutions.com> >Date: Mon, 21 Apr 2025 22:02:05 +0000 >Subject: [PATCH] Bug 31698: Combine item and record level subroutines > >--- > Koha/Hold.pm | 119 +++++++++++++++------------------------------ > reserve/request.pl | 20 +++----- > 2 files changed, 46 insertions(+), 93 deletions(-) > >diff --git a/Koha/Hold.pm b/Koha/Hold.pm >index 1de478c35fd..f76c0189580 100644 >--- a/Koha/Hold.pm >+++ b/Koha/Hold.pm >@@ -178,108 +178,65 @@ sub delete { > return $deleted; > } > >-=head3 move_hold_item >+=head3 move_hold > >-$hold->move_hold_item(); >+$hold->move_hold(); > > =cut > >-sub move_hold_item { >+sub move_hold { > my ( $self, $args ) = @_; > >- my $new_itemnumber = $args->{new_itemnumber}; >- my $new_biblionumber = $args->{new_biblionumber}; >- > my $original = $self; > my $original_biblionumber = $self->biblionumber; > >- my $patron = Koha::Patrons->find( { borrowernumber => $self->borrowernumber } ); >- my $new_item = Koha::Items->find( { itemnumber => $new_itemnumber } ); >- >- if ($new_itemnumber) { >- >- #check to see if moving this hold is allowed >- my $canReserve = >- C4::Reserves::CanItemBeReserved( $patron, $new_item, $self->branchcode, { ignore_hold_counts => 1 } ); >- >- if ( $canReserve->{status} eq 'OK' ) { >- my $max = Koha::Holds->search( >- { biblionumber => $new_biblionumber }, >- { order_by => { -desc => 'priority' }, rows => 1 } >- )->next; >- my $base_priority = $max ? $max->priority : 0; >- my $priority = $base_priority + 1; >- my $new_priority = C4::Reserves::_ShiftPriority( $new_biblionumber, $priority ); >- >- $self->update( >- { >- itemnumber => $new_item->itemnumber, >- biblionumber => $new_item->biblionumber, >- priority => $new_priority, >- } >- ); >- >- C4::Log::logaction( 'HOLDS', 'MODIFY', $self->reserve_id, $self, undef, $original ) >- if C4::Context->preference('HoldsLog'); >- >- return { success => 1, hold => $self }; >- } else { >- return { success => 0, error => $canReserve->{status} }; >- } >- } >- return $self; >-} >- >-=head3 move_hold_biblio >- >-$hold->move_hold_biblio(); >- >-=cut >- >-sub move_hold_biblio { >- my ( $self, $args ) = @_; >+ my $patron = Koha::Patrons->find( { borrowernumber => $self->borrowernumber } ); >+ return { success => 0, error => 'Missing patron or target' } unless $patron; > >- my $new_biblionumber = $args->{new_biblionumber}; >+ my ( $new_biblionumber, $new_itemnumber, $item, $canReserve ); > >- my $original = $self; >- my $original_biblionumber = $self->biblionumber; >+ if ( $args->{new_itemnumber} ) { >+ $item = Koha::Items->find( { itemnumber => $args->{new_itemnumber} } ) >+ or return { success => 0, error => 'Target item not found' }; > >- my $patron = Koha::Patrons->find( { borrowernumber => $self->borrowernumber } ); >+ $new_itemnumber = $item->itemnumber; >+ $new_biblionumber = $item->biblionumber; > >- if ($new_biblionumber) { >+ $canReserve = C4::Reserves::CanItemBeReserved( $patron, $item, $self->branchcode, { ignore_hold_counts => 1 } ); >+ } elsif ( $args->{new_biblionumber} ) { >+ $new_biblionumber = $args->{new_biblionumber}; > >- #check to see if moving this hold is allowed >- my $canReserve = C4::Reserves::CanBookBeReserved( >+ $canReserve = C4::Reserves::CanBookBeReserved( > $patron->borrowernumber, $new_biblionumber, $self->branchcode, > { ignore_hold_counts => 1 } > ); >+ } else { >+ return { success => 0, error => 'Missing itemnumber or biblionumber' }; >+ } > >- if ( $canReserve->{status} eq 'OK' ) { >- my $max = Koha::Holds->search( >- { biblionumber => $new_biblionumber }, >- { order_by => { -desc => 'priority' }, rows => 1 } >- )->next; >- my $base_priority = $max ? $max->priority : 0; >- my $priority = $base_priority + 1; >- my $new_priority = C4::Reserves::_ShiftPriority( $new_biblionumber, $priority ); >- >- $self->update( >- { >- itemnumber => undef, >- biblionumber => $new_biblionumber, >- priority => $new_priority, >- } >- ); >+ return { success => 0, error => $canReserve->{status} } >+ unless $canReserve->{status} eq 'OK'; > >- C4::Log::logaction( 'HOLDS', 'MODIFY', $self->reserve_id, $self, undef, $original ) >- if C4::Context->preference('HoldsLog'); >+ my $max = Koha::Holds->search( >+ { biblionumber => $new_biblionumber }, >+ { order_by => { -desc => 'priority' }, rows => 1 } >+ )->next; >+ my $base_priority = $max ? $max->priority : 0; >+ my $priority = $base_priority + 1; >+ my $new_priority = C4::Reserves::_ShiftPriority( $new_biblionumber, $priority ); > >- return { success => 1, hold => $self }; >- } else { >- return { success => 0, error => $canReserve->{status} }; >+ $self->update( >+ { >+ itemnumber => $new_itemnumber, # undef for biblio-level is fine >+ biblionumber => $new_biblionumber, >+ priority => $new_priority, > } >- } >- return $self; >+ ); >+ >+ C4::Log::logaction( 'HOLDS', 'MODIFY', $self->reserve_id, $self, undef, $original ) >+ if C4::Context->preference('HoldsLog'); >+ >+ return { success => 1, hold => $self }; > } > > =head3 set_transfer >diff --git a/reserve/request.pl b/reserve/request.pl >index 02099434f6f..89c28d1e1dd 100755 >--- a/reserve/request.pl >+++ b/reserve/request.pl >@@ -114,8 +114,7 @@ if ( $op eq 'cud-move' ) { > } elsif ( $op eq 'cud-move_hold_item' or $op eq 'cud-move_hold_biblio' ) { > my @hold_ids = $input->multi_param('hold_id'); > my $original_biblionumber = $input->param('original_biblionumber'); >- >- my @moving_holds = Koha::Holds->search( >+ my @moving_holds = Koha::Holds->search( > { reserve_id => \@hold_ids }, > { order_by => { -asc => 'priority' } } > )->as_list; >@@ -123,16 +122,13 @@ if ( $op eq 'cud-move' ) { > my $new_biblionumber = $input->param('new_biblionumber'); > my $target_biblio = Koha::Biblios->find($new_biblionumber); > >- my $move_method; >- my %args; >+ my %args = ( >+ new_biblionumber => $new_biblionumber, >+ ); > >+ # Only pass new_itemnumber if this is an item level move > if ( $op eq 'cud-move_hold_item' ) { >- $args{new_itemnumber} = $input->param('new_itemnumber'); >- $args{new_biblionumber} = $new_biblionumber; >- $move_method = 'move_hold_item'; >- } else { >- $args{new_biblionumber} = $new_biblionumber; >- $move_method = 'move_hold_biblio'; >+ $args{new_itemnumber} = $input->param('new_itemnumber'); > } > > my @success_messages; >@@ -141,7 +137,7 @@ if ( $op eq 'cud-move' ) { > foreach my $hold (@moving_holds) { > my $original_biblio = Koha::Biblios->find( $hold->biblionumber ); > >- my $result = $hold->$move_method( \%args ); >+ my $result = $hold->move_hold( \%args ); > > if ( $result->{success} ) { > push @success_messages, { >@@ -161,8 +157,8 @@ if ( $op eq 'cud-move' ) { > } > } > >+ #Fix the priority on the original record > C4::Reserves::_FixPriority( { biblionumber => $original_biblionumber } ); >- push @biblionumbers, $original_biblionumber; > > $template->param( > hold_move_successes => \@success_messages, >-- >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 31698
:
179226
|
179235
|
179236
|
179279
|
179287
|
179290
|
179291
|
179292
|
179295
|
179704
|
179711
|
179713
|
181222
|
181223
|
181224
|
181225
|
181226
|
181228
|
181229
|
181230
|
181231
|
181232
|
181233
|
181234
|
181929
|
181930
|
181944
|
181945
|
181946
|
181947
|
181948
|
181951
|
181952
|
181953
|
181954
|
181955
|
181956
|
181957
|
181958
|
181959
|
181960
|
181961
|
181962
|
182639
|
182640
|
182641