Bug 29969: Prevent crash if 'Update holds' clicked after bulk cancellation
If you cancel holds in bulk, the list is not updated as we enqueued the task. But the "Update hold(s)" button will explode if clicked. Test plan: Place several holds on a bib record Use the "Cancel selected" link to cancel holds in bulk The job is enqueued and the hold list still show the holds you cancelled Click "Update holds" => Without this patch you get an ugly 500 Can't call method "found" on an undefined value at /kohadevbox/koha/C4/Reserves.pm line 1060 => With this patch applied the table is refresh, no crash (and there is a warning in the log, that may not be necessary) Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
parent
5433de09c8
commit
450b629ed3
3 changed files with 25 additions and 3 deletions
|
@ -1045,7 +1045,7 @@ sub ModReserve {
|
||||||
my $cancellation_reason = $params->{'cancellation_reason'};
|
my $cancellation_reason = $params->{'cancellation_reason'};
|
||||||
my $date = $params->{expirationdate};
|
my $date = $params->{expirationdate};
|
||||||
|
|
||||||
return if $rank eq "n";
|
return if defined $rank && $rank eq "n";
|
||||||
|
|
||||||
return unless ( $reserve_id || ( $borrowernumber && ( $biblionumber || $itemnumber ) ) );
|
return unless ( $reserve_id || ( $borrowernumber && ( $biblionumber || $itemnumber ) ) );
|
||||||
|
|
||||||
|
@ -1059,6 +1059,9 @@ sub ModReserve {
|
||||||
|
|
||||||
$hold ||= Koha::Holds->find($reserve_id);
|
$hold ||= Koha::Holds->find($reserve_id);
|
||||||
|
|
||||||
|
# FIXME Other calls may fail
|
||||||
|
Koha::Exceptions::ObjectNotFound->throw( 'No hold with id ' . $reserve_id ) unless $hold;
|
||||||
|
|
||||||
if ( $rank eq "del" ) {
|
if ( $rank eq "del" ) {
|
||||||
$hold->cancel({ cancellation_reason => $cancellation_reason });
|
$hold->cancel({ cancellation_reason => $cancellation_reason });
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
use Modern::Perl;
|
use Modern::Perl;
|
||||||
use CGI qw ( -utf8 );
|
use CGI qw ( -utf8 );
|
||||||
use List::MoreUtils qw( uniq );
|
use List::MoreUtils qw( uniq );
|
||||||
|
use Try::Tiny;
|
||||||
|
|
||||||
use C4::Output;
|
use C4::Output;
|
||||||
use C4::Reserves qw( ModReserve ModReserveCancelAll );
|
use C4::Reserves qw( ModReserve ModReserveCancelAll );
|
||||||
use C4::Auth qw( get_template_and_user );
|
use C4::Auth qw( get_template_and_user );
|
||||||
|
@ -83,7 +85,15 @@ else {
|
||||||
$params->{reservedate} = $reservedates[$i] ? dt_from_string($reservedates[$i]) : undef;
|
$params->{reservedate} = $reservedates[$i] ? dt_from_string($reservedates[$i]) : undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
ModReserve($params);
|
ModReserve($params);
|
||||||
|
} catch {
|
||||||
|
if ($_->isa('Koha::Exceptions::ObjectNotFound')){
|
||||||
|
warn $_;
|
||||||
|
} else {
|
||||||
|
$_->rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,9 @@ use t::lib::TestBuilder;
|
||||||
|
|
||||||
use C4::Context;
|
use C4::Context;
|
||||||
|
|
||||||
use Test::More tests => 72;
|
use Test::More tests => 73;
|
||||||
|
use Test::Exception;
|
||||||
|
|
||||||
use MARC::Record;
|
use MARC::Record;
|
||||||
|
|
||||||
use C4::Biblio;
|
use C4::Biblio;
|
||||||
|
@ -223,6 +225,13 @@ AlterPriority( 'bottom', $hold->reserve_id, undef, 2, 1, 6 );
|
||||||
$hold = Koha::Holds->find( $reserveid );
|
$hold = Koha::Holds->find( $reserveid );
|
||||||
is( $hold->priority, '6', "Test AlterPriority(), move to bottom" );
|
is( $hold->priority, '6', "Test AlterPriority(), move to bottom" );
|
||||||
|
|
||||||
|
|
||||||
|
$hold->delete;
|
||||||
|
throws_ok
|
||||||
|
{ C4::Reserves::ModReserve({ reserve_id => $hold->reserve_id }) }
|
||||||
|
'Koha::Exceptions::ObjectNotFound',
|
||||||
|
'No hold with id ' . $hold->reserve_id;
|
||||||
|
|
||||||
# Regression test for bug 2394
|
# Regression test for bug 2394
|
||||||
#
|
#
|
||||||
# If IndependentBranches is ON and canreservefromotherbranches is OFF,
|
# If IndependentBranches is ON and canreservefromotherbranches is OFF,
|
||||||
|
|
Loading…
Reference in a new issue