Bug 18851: Database handler must not be created at runtime
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 5 Jul 2017 20:37:41 +0000 (17:37 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 8 Aug 2017 12:21:05 +0000 (09:21 -0300)
Signed-off-by: Mirko Tietgen <mirko@abunchofthings.net>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/Patron/Discharge.pm

index 580d4d1..06e3101 100644 (file)
@@ -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;
 }