From 77cc94f41b62590f26b8d989292fbc379c47b974 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 10 May 2023 19:25:21 +0100 Subject: [PATCH] Bug 12532: (QA follow-up) Clean up notice_email_address Reduce some of the code duplication Signed-off-by: Martin Renvoize --- Koha/Patron.pm | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 3a94bf823d8..4b4d4dd2995 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1426,33 +1426,32 @@ Returns the empty string if no email address. =cut -sub notice_email_address{ - my ( $self ) = @_; +sub notice_email_address { + my ($self) = @_; my $address; my $guarantor_address; my $which_address = C4::Context->preference("EmailFieldPrimary"); + # if syspref is set to 'first valid' (value == OFF), look up email address if ( $which_address eq 'OFF' ) { $address = $self->first_valid_email_address; - } else { + } + else { $address = $self->$which_address || ''; } my $use_guarantor = C4::Context->preference('RedirectGuaranteeEmail'); if ($use_guarantor) { - my @guarantors = map { $_->guarantors->as_list } $self->guarantor_relationships(); + my @guarantors = + map { $_->guarantors->as_list } $self->guarantor_relationships(); if (@guarantors) { foreach my $guarantor (@guarantors) { - if ( $which_address eq 'OFF' ) { - $guarantor_address = $guarantor->first_valid_email_address; - } else { - $guarantor_address = $guarantor->$which_address || ''; - } - if ($address){ + $guarantor_address = $guarantor->notice_email_address; + if ($address) { $address .= ', '; } - $address .= $guarantor_address if $guarantor_address; + $address .= $guarantor_address if $guarantor_address; } } } -- 2.41.0