Bug 29145: (QA follow-up) Use objects instead of straight SQL queries

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Kyle M Hall 2023-01-27 14:36:40 +00:00 committed by Tomas Cohen Arazi
parent 91ecb7405e
commit 67bcdeed28
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
4 changed files with 116 additions and 19 deletions

40
Koha/OverdueRule.pm Normal file
View File

@ -0,0 +1,40 @@
package Koha::OverdueRule;
# Copyright ByWater Solutions 2023
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use base qw(Koha::Object);
=head1 NAME
Koha::OverdueRule - Koha Overdue rule object class
=head1 API
=head2 Class Methods
=head3 _type
=cut
sub _type {
return 'Overduerule';
}
1;

50
Koha/OverdueRules.pm Normal file
View File

@ -0,0 +1,50 @@
package Koha::OverdueRules;
# Copyright ByWater Solutions 2023
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Koha::OverdueRule;
use base qw(Koha::Objects);
=head1 NAME
Koha::OverdueRules - Koha::OverdueRule Object set class
=head1 API
=head2 Class Methods
=head3 _type
=cut
sub _type {
return 'Overduerule';
}
=head3 object_class
=cut
sub object_class {
return 'Koha::OverdueRule';
}
1;

View File

@ -25,23 +25,24 @@ use JSON qw( to_json );
use Unicode::Normalize qw( NFKD );
use Try::Tiny;
use C4::Context;
use C4::Auth qw( checkpw_hash );
use C4::Context;
use C4::Letters qw( GetPreparedLetter EnqueueLetter SendQueuedMessages );
use C4::Log qw( logaction );
use Koha::Account;
use Koha::ArticleRequests;
use C4::Letters qw( GetPreparedLetter EnqueueLetter SendQueuedMessages );
use Koha::AuthUtils;
use Koha::Checkouts;
use Koha::CirculationRules;
use Koha::Club::Enrollments;
use Koha::CurbsidePickups;
use Koha::Database;
use Koha::DateUtils qw( dt_from_string );
use Koha::Encryption;
use Koha::Exceptions::Password;
use Koha::Holds;
use Koha::CurbsidePickups;
use Koha::Old::Checkouts;
use Koha::OverdueRules;
use Koha::Patron::Attributes;
use Koha::Patron::Categories;
use Koha::Patron::Debarments;
@ -1073,23 +1074,24 @@ sub _get_overdue_debarred_delay {
my ($branchcode, $categorycode) = @_;
my $dbh = C4::Context->dbh();
my $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = ? AND categorycode = ?";
my $rqoverduerules = $dbh->prepare($query);
$rqoverduerules->execute($branchcode, $categorycode);
# We get default rules if there is no rule for this branch
if($rqoverduerules->rows == 0) {
$query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = '' AND categorycode = ?";
my $rule = Koha::OverdueRules->find(
{
branchcode => $branchcode,
categorycode => $categorycode
}
)
|| Koha::OverdueRules->find(
{
branchcode => q{},
categorycode => $categorycode
}
);
$rqoverduerules = $dbh->prepare($query);
$rqoverduerules->execute($categorycode);
}
while ( my $overdue_rules = $rqoverduerules->fetchrow_hashref ) {
return $overdue_rules->{"delay1"} if($overdue_rules->{"debarred1"});
return $overdue_rules->{"delay2"} if($overdue_rules->{"debarred2"});
return $overdue_rules->{"delay3"} if($overdue_rules->{"debarred3"});
if ( $rule ) {
return $rule->delay1 if $rule->debarred1;
return $rule->delay2 if $rule->debarred2;
return $rule->delay3 if $rule->debarred3;
}
}

View File

@ -198,6 +198,11 @@ __PACKAGE__->has_many(
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:pORigxtC5qztZWHI29mZ/g
sub koha_object_class {
'Koha::OverdueRule';
}
sub koha_objects_class {
'Koha::OverdueRules';
}
# You can replace this text with custom content, and it will be preserved on regeneration
1;