From f79beb52708ed211f4ef6386ed358b21ed511efb Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 5 Jul 2017 17:37:41 -0300 Subject: [PATCH] Bug 18851: Database handler must not be created at runtime Signed-off-by: Mirko Tietgen Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart --- Koha/Patron/Discharge.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Koha/Patron/Discharge.pm b/Koha/Patron/Discharge.pm index 580d4d1441..06e3101991 100644 --- a/Koha/Patron/Discharge.pm +++ b/Koha/Patron/Discharge.pm @@ -13,8 +13,6 @@ use Koha::Database; use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Patrons; -my $rs = Koha::Database->new->schema->resultset('Discharge'); - sub count { my ($params) = @_; my $values = {}; @@ -30,6 +28,7 @@ sub count { $values->{validated} = { '!=', undef }; } + my $rs = Koha::Database->new->schema->resultset('Discharge'); return $rs->search( $values )->count; } @@ -67,6 +66,7 @@ sub request { return unless $borrowernumber; return unless can_be_discharged({ borrowernumber => $borrowernumber }); + my $rs = Koha::Database->new->schema->resultset('Discharge'); return $rs->create({ borrower => $borrowernumber, needed => dt_from_string, @@ -92,6 +92,7 @@ sub discharge { }); # Generate the discharge + my $rs = Koha::Database->new->schema->resultset('Discharge'); my $discharge = $rs->search({ borrower => $borrowernumber }, { order_by => { -desc => 'needed' }, rows => 1 }); if( $discharge->count > 0 ) { $discharge->update({ validated => dt_from_string }); @@ -163,6 +164,7 @@ sub get_pendings { ( defined $branchcode ? ( 'borrower.branchcode' => $branchcode ) : () ), }; + my $rs = Koha::Database->new->schema->resultset('Discharge'); my @rs = $rs->search( $cond, { join => 'borrower' } ); return \@rs; } @@ -178,6 +180,7 @@ sub get_validated { ( defined $branchcode ? ( 'borrower.branchcode' => $branchcode ) : () ), }; + my $rs = Koha::Database->new->schema->resultset('Discharge'); my @rs = $rs->search( $cond, { join => 'borrower' } ); return \@rs; } -- 2.39.5