From 2b106c1181fd970e9aeef53bf6ab19592f61592c Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 22 Apr 2024 00:07:30 -0300 Subject: [PATCH] Bug 25996: Make AddDebarment() use Koha::Patron::Restriction This patch makes the AddDebarment() method use the Koha::Object-based class to ease the next steps. The current codebase makes the feature fragile otherwise, as adding a new row and then querying for the latest row of that kind seems risky, With this approach the result is the same, but we have the Koha::Patron::Restriction object for using it later in logging. I opted to return 1 as it does now. The whole module deserves to be removed in the future but it is out of the scope of this report. To test: 1. Run: $ ktd --shell k$ prove t/db_dependent/Patron/Borrower_Debarments.t => SUCCESS: Tests pass 2. Apply this tiny refactoring patch 3. Repeat 1 => SUCCESS: Tests still pass! 4. Sign off :-D Sponsored-by: Karlsruhe Institute of Technology (KIT) Signed-off-by: Michaela Sieber Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- Koha/Patron/Debarments.pm | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Koha/Patron/Debarments.pm b/Koha/Patron/Debarments.pm index e866dc2ea7..2ac587307f 100644 --- a/Koha/Patron/Debarments.pm +++ b/Koha/Patron/Debarments.pm @@ -22,6 +22,7 @@ use Modern::Perl; use C4::Context; use Koha::Patron::Restriction::Types; +use Koha::Patron::Restrictions; our ( @ISA, @EXPORT_OK ); @@ -73,16 +74,19 @@ sub AddDebarment { my $manager_id; $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; - my $sql = " - INSERT INTO borrower_debarments ( borrowernumber, expiration, type, comment, manager_id, created ) - VALUES ( ?, ?, ?, ?, ?, NOW() ) - "; - - my $r = C4::Context->dbh->do( $sql, {}, ( $borrowernumber, $expiration, $type, $comment, $manager_id ) ); + my $restriction = Koha::Patron::Restriction->new( + { + borrowernumber => $borrowernumber, + expiration => $expiration, + type => $type, + comment => $comment, + manager_id => $manager_id, + } + )->store(); UpdateBorrowerDebarmentFlags($borrowernumber); - return $r; + return $restriction ? 1 : 0; } =head2 DelDebarment -- 2.39.5