From 9493b1c5176e646f5b51e468cb1897c6158d76f0 Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Wed, 10 May 2023 13:53:20 +0200
Subject: [PATCH] Bug 33578: Fix controller when editing a restriction type
Content-Type: text/plain; charset=utf-8

Do not display a warning when we are editing a restriction type and no
other types with this description exists.

Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
---
 admin/restrictions.pl | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/admin/restrictions.pl b/admin/restrictions.pl
index 06812c0bfa..ab0c384212 100755
--- a/admin/restrictions.pl
+++ b/admin/restrictions.pl
@@ -58,10 +58,13 @@ if ( $op eq 'add_form') {
 
     if ($is_a_modif) {
         # Check whether another restriction already has this display text
-        my $dupe = Koha::Patron::Restriction::Types->find({
-            display_text => $display_text
-        });
-        if ($dupe) {
+        my $dupe = Koha::Patron::Restriction::Types->search(
+            {
+                code         => { '!=' => $code },
+                display_text => $display_text,
+            }
+        );
+        if ($dupe->count) {
             push @messages, {
                 type => 'error', code => 'duplicate_display_text'
             };
-- 
2.30.2