From 29f97af009226c880df8844229b9c3cff47a71be Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 19 Dec 2023 17:09:17 +0000 Subject: [PATCH] Bug 12802: (alt) Update notice_email_address method to return a list This patch updates the notice_email_address method to return a comma separated list of addresses as expected by Email::Sender if you wish to send mail to multiple To addresses. --- Koha/Patron.pm | 15 +++++++++++---- t/db_dependent/Koha/Patron.t | 5 ++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 1a4a9205806..b1f3f972de4 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1616,12 +1616,19 @@ 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; + my @addresses; + for my $email_field ( split ",", $which_address ) { + + # if syspref is set to 'first valid' (value == OFF), look up email address + if ( $email_field eq 'OFF' ) { + return $self->first_valid_email_address; + } + + my $email_address = $self->$email_field; + push @addresses, $email_address if $email_address; } - return $self->$which_address || ''; + return join(",",@addresses); } =head3 first_valid_email_address diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index e07e90eaf82..583d61f292f 100755 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -1790,7 +1790,7 @@ subtest 'notify_library_of_registration()' => sub { }; subtest 'notice_email_address' => sub { - plan tests => 2; + plan tests => 3; $schema->storage->txn_begin; my $patron = $builder->build_object({ class => 'Koha::Patrons' }); @@ -1802,6 +1802,9 @@ subtest 'notice_email_address' => sub { t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'emailpro' ); is ($patron->notice_email_address, $patron->emailpro, "Koha::Patron->notice_email_address returns correct value when EmailFieldPrimary is emailpro"); + t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'email,emailpro' ); + is ($patron->notice_email_address, $patron->email.",".$patron->emailpro, "Koha::Patron->notice_email_address returns correct value when EmailFieldPrimary is email|emailpro"); + $patron->delete; $schema->storage->txn_rollback; }; -- 2.30.2