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 <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit b262e350f1)
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Tomas Cohen Arazi 2024-08-28 15:01:37 -03:00 committed by Lucas Gass
parent d3de26092e
commit f5c0c34754
1 changed files with 7 additions and 9 deletions

View File

@ -1655,22 +1655,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' ) {
@ -1680,11 +1679,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