From 87b166e38167a6f0cf1c58881956d03f620813c7 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 11 Oct 2019 08:20:24 +0100 Subject: [PATCH] Bug 23049: More thorough param checking MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Séverine QUEUNE Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize --- Koha/Account.pm | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Koha/Account.pm b/Koha/Account.pm index f63d442d5d..2a8d557235 100644 --- a/Koha/Account.pm +++ b/Koha/Account.pm @@ -465,9 +465,17 @@ sub add_debit { my ( $self, $params ) = @_; + # check for mandatory params + my @mandatory = ( 'interface', 'type', 'amount' ); + for my $param (@mandatory) { + unless ( defined( $params->{$param} ) ) { + Koha::Exceptions::MissingParameter->throw( + error => "The $param parameter is mandatory" ); + } + } + # amount should always be a positive value my $amount = $params->{amount}; - unless ( $amount > 0 ) { Koha::Exceptions::Account::AmountNotPositive->throw( error => 'Debit amount passed is not positive' ); @@ -481,17 +489,10 @@ sub add_debit { my $debit_type = $params->{type}; my $item_id = $params->{item_id}; my $issue_id = $params->{issue_id}; - - unless ($interface) { - Koha::Exceptions::MissingParameter->throw( - error => 'The interface parameter is mandatory' ); - } - - my $schema = Koha::Database->new->schema; - my $offset_type = $Koha::Account::offset_type->{$debit_type} // 'Manual Debit'; my $line; + my $schema = Koha::Database->new->schema; try { $schema->txn_do( sub { -- 2.39.5