From 8f389f3053af050835d573f75f762bda2f6d945a Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 28 Aug 2024 15:01:37 -0300 Subject: [PATCH] Bug 37757: Make notice_email_address() handle EmailFieldPrimary values more robustly This patchset makes: * The EmailFieldPrimary value 'OFF' be replaced by an empty string * Koha::Patron->notice_email_address() handle the empty case more gracefully To test: 1. On main, manually set the EmailFieldPrimary syspref to empty $ ktd --shell k$ koha-mysql kohadev > UPDATE systempreferences SET value='' WHERE variable='EmailFieldPrimary'; 2. Enable `AutoEmailNewUser` 3. Create a new user => FAIL: Koha explodes like: ``` The method Koha::Patron-> is not covered by tests! Trace begun at /kohadevbox/koha/Koha/Object.pm line 992 Koha::Object::AUTOLOAD('Koha::Patron=HASH(0xaaaae37ac550)') called at /kohadevbox/koha/Koha/Patron.pm line 1662 Koha::Patron::notice_email_address('Koha::Patron=HASH(0xaaaae37ac550)') called at /kohadevbox/koha/members/memberentry.pl line 448 ... 4. Apply this patches 5. Run: k$ updatedatabase => SUCCESS: Update succeeds 6. Restart all and retry creating a patron => SUCCESS: It worked! 7. Sign off :-D Signed-off-by: David Nind --- Koha/Patron.pm | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 3e4e89c799..dde7d73d1a 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1630,22 +1630,21 @@ sub return_claims { =head3 notice_email_address - my $email = $patron->notice_email_address; + my $email = $patron->notice_email_address; Return the email address of patron used for notices. Returns the empty string if no email address. =cut -sub notice_email_address{ - my ( $self ) = @_; +sub notice_email_address { + my ($self) = @_; 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' ) { - return $self->first_valid_email_address; - } + # if syspref is set to 'first valid', look up email address + return $self->first_valid_email_address + unless $which_address; # if syspref is set to 'selected addresses' (value == MULTI), look up email addresses if ( $which_address eq 'MULTI' ) { @@ -1655,11 +1654,10 @@ sub notice_email_address{ my $email_address = $self->$email_field; push @addresses, $email_address if $email_address; } - return join(",",@addresses); + return join( ",", @addresses ); } return $self->$which_address || ''; - } =head3 first_valid_email_address -- 2.39.2