From 4003fa41ba79b086acb168e732842cab1d10cc65 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 20 Jan 2014 16:49:11 +0100 Subject: [PATCH] Bug 10827: Change prototype for ModReserveAffect This patch only changes the prototype for C4::Reserves::ModReserveAffect. This modification will allow to simplify future changes. No change should be expected with this patch. Signed-off-by: Kyle M Hall --- C4/Reserves.pm | 14 +++++++++----- C4/SIP/ILS/Transaction/Checkin.pm | 14 ++++++++++---- circ/branchtransfers.pl | 2 +- circ/returns.pl | 2 +- t/db_dependent/Reserves.t | 6 +++--- t/db_dependent/Reserves/priorities.t | 6 +++--- 6 files changed, 27 insertions(+), 17 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 8fe0fd0..724549b 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1228,21 +1228,25 @@ sub ModReserveStatus { =head2 ModReserveAffect - &ModReserveAffect($itemnumber,$borrowernumber,$diffBranchSend); + &ModReserveAffect({ itemnumber => $itemnumber, borrowernumber => $borrowernumber, force_transfer => $diffBranchSend }); This function affect an item and a status for a given reserve The itemnumber parameter is used to find the biblionumber. with the biblionumber & the borrowernumber, we can affect the itemnumber to the correct reserve. -if $transferToDo is not set, then the status is set to "Waiting" as well. +if $force_transfer is not set, then the status is set to "Waiting" as well. otherwise, a transfer is on the way, and the end of the transfer will take care of the waiting status =cut sub ModReserveAffect { - my ( $itemnumber, $borrowernumber,$transferToDo ) = @_; + my ( $params ) = @_; + my $borrowernumber = $params->{borrowernumber}; + my $itemnumber = $params->{itemnumber}; + my $force_transfer = $params->{force_transfer}; + my $dbh = C4::Context->dbh; # we want to attach $itemnumber to $borrowernumber, find the biblionumber @@ -1263,7 +1267,7 @@ sub ModReserveAffect { # If we affect a reserve that has to be transfered, don't set to Waiting my $query; - if ($transferToDo) { + if ( $force_transfer ) { $query = " UPDATE reserves SET priority = 0, @@ -1287,7 +1291,7 @@ sub ModReserveAffect { } $sth = $dbh->prepare($query); $sth->execute( $itemnumber, $borrowernumber,$biblionumber); - _koha_notify_reserve( $itemnumber, $borrowernumber, $biblionumber ) if ( !$transferToDo && !$already_on_shelf ); + _koha_notify_reserve( $itemnumber, $borrowernumber, $biblionumber ) if ( !$force_transfer && !$already_on_shelf ); if ( C4::Context->preference("ReturnToShelvingCart") ) { CartToShelf( $itemnumber ); diff --git a/C4/SIP/ILS/Transaction/Checkin.pm b/C4/SIP/ILS/Transaction/Checkin.pm index db1f102..b833cd1 100644 --- a/C4/SIP/ILS/Transaction/Checkin.pm +++ b/C4/SIP/ILS/Transaction/Checkin.pm @@ -82,13 +82,19 @@ sub do_checkin { $self->hold($messages->{ResFound}); if ($branch eq $messages->{ResFound}->{branchcode}) { $self->alert_type('01'); - ModReserveAffect( $messages->{ResFound}->{itemnumber}, - $messages->{ResFound}->{borrowernumber}, 0); + ModReserveAffect({ + itemnumber => $messages->{ResFound}->{itemnumber}, + borrowernumber => $messages->{ResFound}->{borrowernumber}, + force_transfer => 0 + }); } else { $self->alert_type('02'); - ModReserveAffect( $messages->{ResFound}->{itemnumber}, - $messages->{ResFound}->{borrowernumber}, 1); + ModReserveAffect({ + itemnumber => $messages->{ResFound}->{itemnumber}, + borrowernumber => $messages->{ResFound}->{borrowernumber}, + force_transfer => 1 + }); ModItemTransfer( $messages->{ResFound}->{itemnumber}, $branch, $messages->{ResFound}->{branchcode} diff --git a/circ/branchtransfers.pl b/circ/branchtransfers.pl index 3be7bb4..496ca15 100755 --- a/circ/branchtransfers.pl +++ b/circ/branchtransfers.pl @@ -89,7 +89,7 @@ if ( $request eq "KillWaiting" ) { } elsif ( $request eq "SetWaiting" ) { my $item = $query->param('itemnumber'); - ModReserveAffect( $item, $borrowernumber ); + ModReserveAffect({ itemnumber => $item, borrowernumber => $borrowernumber, force_transfer => 0 }); $ignoreRs = 1; $setwaiting = 1; $reqmessage = 1; diff --git a/circ/returns.pl b/circ/returns.pl index 93f36f2..2693f53 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -142,7 +142,7 @@ if ( $query->param('resbarcode') ) { my $diffBranchSend = ($userenv_branch ne $diffBranchReturned) ? $diffBranchReturned : undef; # diffBranchSend tells ModReserveAffect whether document is expected in this library or not, # i.e., whether to apply waiting status - ModReserveAffect( $item, $borrowernumber, $diffBranchSend); + ModReserveAffect({ itemnumber => $item, borrowernumber => $borrowernumber, force_transfer => $diffBranchSend }); # check if we have other reserves for this document, if we have a return send the message of transfer my ( $messages, $nextreservinfo ) = GetOtherReserves($item); diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index db82296..8db64aa 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -271,12 +271,12 @@ is(exists $messages->{ResFound}?1:0, 1, 'AddReturn considers future reserve with # test marking a hold as captured my $hold_notice_count = count_hold_print_messages(); -ModReserveAffect($itemnumber, $requesters{'CPL'}, 0); +ModReserveAffect({ itemnumber => $itemnumber, borrowernumber => $requesters{'CPL'}, force_transfer => 0 }); my $new_count = count_hold_print_messages(); is($new_count, $hold_notice_count + 1, 'patron notified when item set to waiting'); # test that duplicate notices aren't generated -ModReserveAffect($itemnumber, $requesters{'CPL'}, 0); +ModReserveAffect({ itemnumber => $itemnumber, borrowernumber => $requesters{'CPL'}, force_transfer => 0 }); $new_count = count_hold_print_messages(); is($new_count, $hold_notice_count + 1, 'patron not notified a second time (bug 11445)'); @@ -312,7 +312,7 @@ AddReserve('CPL', $requesters{'CPL'}, $bibnum, @results= GetReservesFromItemnumber($itemnumber); is(defined $results[3]?1:0, 0, 'GetReservesFromItemnumber does not return a future item level hold'); # 9788c: GetReservesFromItemnumber returns future wait (confirmed future hold) -ModReserveAffect( $itemnumber, $requesters{'CPL'} , 0); #confirm hold +ModReserveAffect({ itemnumber => $itemnumber, borrowernumber => $requesters{'CPL'} , force_transfer => 0 }); #confirm hold @results= GetReservesFromItemnumber($itemnumber); is(defined $results[3]?1:0, 1, 'GetReservesFromItemnumber returns a future wait (confirmed future hold)'); # End of tests for bug 9788 diff --git a/t/db_dependent/Reserves/priorities.t b/t/db_dependent/Reserves/priorities.t index c02bfee..700dbb9 100644 --- a/t/db_dependent/Reserves/priorities.t +++ b/t/db_dependent/Reserves/priorities.t @@ -59,7 +59,7 @@ AddReserve( 'CPL', $borrowernumber3, $biblionumber, 'a', undef, 2, undef, undef, ( $reserve2 ) = GetReservesFromBorrowernumber( $borrowernumber2 ); AddReturn( $barcode1 ); -ModReserveAffect( $itemnumber1, $borrowernumber2 ); +ModReserveAffect({ itemnumber => $itemnumber1, borrowernumber => $borrowernumber2 }); ( $reserve2 ) = GetReservesFromBorrowernumber( $borrowernumber2 ); is( $reserve2->{borrowernumber}, $borrowernumber2 ); @@ -96,7 +96,7 @@ AddReserve( 'CPL', $borrowernumber2, $biblionumber, 'a', undef, 1); AddReserve( 'CPL', $borrowernumber3, $biblionumber, 'a', undef, 2 ); C4::Context->set_preference('ConfirmFutureHolds', 2); my ( undef, $message ) = AddReturn( $barcode1 ); -ModReserveAffect( $itemnumber1, $borrowernumber2 ); +ModReserveAffect({ itemnumber => $itemnumber1, borrowernumber => $borrowernumber2 }); ( $reserve2 ) = GetReservesFromBorrowernumber( $borrowernumber2 ); is( $reserve2->{borrowernumber}, $borrowernumber2 ); @@ -135,7 +135,7 @@ AddReserve( 'MPL', $borrowernumber3, $biblionumber, 'a', undef, 2, undef, undef, ( $reserve2 ) = GetReservesFromBorrowernumber( $borrowernumber2 ); AddReturn( $barcode1 ); -ModReserveAffect( $itemnumber2, $borrowernumber2, 1 ); +ModReserveAffect({ itemnumber => $itemnumber2, borrowernumber => $borrowernumber2, force_transfer => 1 }); ( $reserve2 ) = GetReservesFromBorrowernumber( $borrowernumber2 ); is( $reserve2->{borrowernumber}, $borrowernumber2 ); -- 1.7.2.5