From 02883ee76d637867d8461f1ba892c146e4ca9926 Mon Sep 17 00:00:00 2001 From: Baptiste Wojtkowski Date: Wed, 11 Sep 2024 11:54:38 +0200 Subject: [PATCH] Bug 37881: Editing patron with guarantor won't crash This patch fixes issue introduced by BZ32530 Test Plan (on main): 1 - Edit a patron 2 - Do not change anything and submit -> you get an error 3 - Apply both patches 4 - Repeat 1&2 -> everything works fine 5 - Try and delete the guarantor -> it will be deleted --- members/memberentry.pl | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/members/memberentry.pl b/members/memberentry.pl index 2fa5447..5c561d3 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -940,11 +940,18 @@ sub add_guarantors { next unless $guarantor_id; - $patron->add_guarantor( - { + my $existing_relationship_count = Koha::Patron::Relationships->search({ + guarantee_id => $patron->id, guarantor_id => $guarantor_id, - relationship => $relationship, - } - ); + })->count; + + if ( $existing_relationship_count == 0 ){ + $patron->add_guarantor( + { + guarantor_id => $guarantor_id, + relationship => $relationship, + } + ); + } } } -- 2.43.0