From ef3970cd2e083049f74b22d91375a450536f08aa Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 25 Aug 2022 10:22:39 +0100 Subject: [PATCH] Bug 31095: Remove GetDebarments from Koha::Patron::Debarments This patch finally removes GetDebarments from the codebase. Test plan 1. Confirm GetDebarments is no longer mentioned in the codebase. `git grep GetDebarments` 2. Confirm t/db_dependent/Patron/Borrower_Debarments.t continues to pass Signed-off-by: Nick Clemens Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 7c1ffd2b11501fdcedb8e7dd2e2838283c847ede) Signed-off-by: Matt Blenkinsop --- Koha/Patron/Debarments.pm | 46 +++++++++++++-------------------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/Koha/Patron/Debarments.pm b/Koha/Patron/Debarments.pm index 52e1036850..60c3f5504e 100644 --- a/Koha/Patron/Debarments.pm +++ b/Koha/Patron/Debarments.pm @@ -27,8 +27,6 @@ BEGIN { require Exporter; @ISA = qw(Exporter); @EXPORT_OK = qw( - GetDebarments - AddDebarment DelDebarment ModDebarment @@ -45,28 +43,6 @@ Koha::Patron::Debarments - Module for managing patron debarments =cut -=head2 GetDebarments - -my $arrayref = GetDebarments({ borrowernumber => $borrowernumber [, key => $value ] ); - -=cut - -sub GetDebarments { - my ($params) = @_; - - return unless ( $params->{'borrowernumber'} ); - - my @keys = keys %$params; - my @values = values %$params; - - my $where = join( ' AND ', map { "$_ = ?" } @keys ); - my $sql = "SELECT * FROM borrower_debarments WHERE $where"; - my $sth = C4::Context->dbh->prepare($sql); - $sth->execute(@values); - - return $sth->fetchall_arrayref( {} ); -} - =head2 AddDebarment my $success = AddDebarment({ @@ -197,18 +173,22 @@ sub AddUniqueDebarment { return unless ( $borrowernumber && $type ); - my $debarment = @{ GetDebarments( { borrowernumber => $borrowernumber, type => $type } ) }[0]; + my $patron = Koha::Patrons->find($borrowernumber); + return unless $patron; + + my $debarment = + $patron->restrictions->search( { type => $type }, { rows => 1 } )->single; my $r; if ($debarment) { # We don't want to shorten a unique debarment's period, so if this 'update' would do so, just keep the current expiration date instead - $params->{'expiration'} = $debarment->{'expiration'} - if ( $debarment->{'expiration'} - && $debarment->{'expiration'} gt $params->{'expiration'} ); + $params->{'expiration'} = $debarment->expiration + if ( $debarment->expiration + && $debarment->expiration gt $params->{'expiration'} ); $params->{'borrower_debarment_id'} = - $debarment->{'borrower_debarment_id'}; + $debarment->borrower_debarment_id; $r = ModDebarment($params); } else { @@ -242,11 +222,15 @@ sub DelUniqueDebarment { return unless ( $borrowernumber && $type ); - my $debarment = @{ GetDebarments( { borrowernumber => $borrowernumber, type => $type } ) }[0]; + my $patron = Koha::Patrons->find($borrowernumber); + return unless $patron; + + my $debarment = + $patron->restrictions->search( { type => $type }, { rows => 1 } )->single; return unless ( $debarment ); - return DelDebarment( $debarment->{'borrower_debarment_id'} ); + return DelDebarment( $debarment->borrower_debarment_id ); } =head2 UpdateBorrowerDebarmentFlags -- 2.39.5