Bug 31095: Remove GetDebarments from Patron::Import
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 25 Aug 2022 07:56:54 +0000 (08:56 +0100)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 31 Jan 2023 13:19:38 +0000 (10:19 -0300)
This patch replaced GetDebarments with $patron->restrictions->search in
Koha::Patron::Import.

Test plan
1. Confirm that importing patrons with debarred and debarredcomment
   fields in the import still works as expected

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Koha/Patrons/Import.pm

index 6f62cc1..3ba184d 100644 (file)
@@ -29,7 +29,7 @@ use C4::Letters qw( GetPreparedLetter EnqueueLetter );
 use Koha::Libraries;
 use Koha::Patrons;
 use Koha::Patron::Categories;
-use Koha::Patron::Debarments qw( AddDebarment GetDebarments );
+use Koha::Patron::Debarments qw( AddDebarment );
 use Koha::DateUtils qw( dt_from_string output_pref );
 
 =head1 NAME
@@ -293,16 +293,15 @@ sub import_patrons {
                     if ( $borrower{debarred} && ( ( $borrower{debarred} ne $member->{debarred} ) || ( $borrower{debarredcomment} ne $member->{debarredcomment} ) ) ) {
 
                         # Check to see if this debarment already exists
-                        my $debarrments = GetDebarments(
+                        my $restrictions = $patron->restrictions->search(
                             {
-                                borrowernumber => $borrowernumber,
-                                expiration     => $borrower{debarred},
-                                comment        => $borrower{debarredcomment}
+                                expiration => $borrower{debarred},
+                                comment    => $borrower{debarredcomment}
                             }
                         );
 
                         # If it doesn't, then add it!
-                        unless (@$debarrments) {
+                        unless ($restrictions->count) {
                             AddDebarment(
                                 {
                                     borrowernumber => $borrowernumber,