From b12f857f4a88c9a51eb68c74486a9b050315569c Mon Sep 17 00:00:00 2001 From: Kyle Hall Date: Mon, 28 Feb 2022 09:03:29 -0500 Subject: [PATCH] Bug 17648: ACCTDETAILS notice does not show in notices.pl The ACCTDETAILS notice apparently bypasses message_queue; notices are sent directly to the linux mail queue. Test Plan: 1) Apply this patch 2) Create a new patron with an email address 3) Note the patron's ACCTDETAILS notice shows in the patron's messages Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer Signed-off-by: Fridolin Somers Signed-off-by: Kyle M Hall --- C4/Letters.pm | 50 ------------------------------------------ members/memberentry.pl | 29 ++++++++++++++++++------ 2 files changed, 22 insertions(+), 57 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index c36553ac9a..2a9893555d 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -529,56 +529,6 @@ sub SendAlerts { . $letter->{content} ) if C4::Context->preference("ClaimsLog"); } - # send an "account details" notice to a newly created user - elsif ( $type eq 'members' ) { - my $library = Koha::Libraries->find( $externalid->{branchcode} ); - my $letter = GetPreparedLetter ( - module => 'members', - letter_code => $letter_code, - branchcode => $externalid->{'branchcode'}, - lang => $externalid->{lang} || 'default', - tables => { - 'branches' => $library->unblessed, - 'borrowers' => $externalid->{'borrowernumber'}, - }, - substitute => { 'borrowers.password' => $externalid->{'password'} }, - want_librarian => 1, - ) or return; - return { error => "no_email" } unless $externalid->{'emailaddr'}; - - my $success = try { - - # FIXME: This 'default' behaviour should be moved to Koha::Email - my $mail = Koha::Email->create( - { - to => $externalid->{'emailaddr'}, - from => $library->branchemail, - reply_to => $library->branchreplyto, - sender => $library->branchreturnpath, - subject => "" . $letter->{'title'}, - } - ); - - if ( $letter->{is_html} ) { - $mail->html_body( _wrap_html( $letter->{content}, "" . $letter->{title} ) ); - } - else { - $mail->text_body( $letter->{content} ); - } - - $mail->send_or_die({ transport => $library->smtp_server->transport }); - } - catch { - # We expect ref($_) eq 'Email::Sender::Failure' - $error = $_->message; - - carp "$_"; - return; - }; - - return { error => $error } - unless $success; - } # If we come here, return an OK status return 1; diff --git a/members/memberentry.pl b/members/memberentry.pl index 2485b32a71..14eb2d7715 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -481,14 +481,29 @@ if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ $newdata{emailaddr} = $emailaddr; my $err; eval { - $err = SendAlerts ( 'members', \%newdata, "ACCTDETAILS" ); + my $letter = GetPreparedLetter( + module => 'members', + letter_code => 'ACCTDETAILS', + branchcode => $patron->branchcode,, + lang => $patron->lang || 'default', + tables => { + 'branches' => $patron->branchcode, + 'borrowers' => $patron->borrowernumber, + }, + want_librarian => 1, + ) or return; + + my $success = EnqueueLetter( + { + letter => $letter, + borrowernumber => $patron->id, + to_address => $emailaddr, + message_transport_type => 'email' + } + ); }; - if ( $@ ) { - $template->param(error_alert => $@); - } elsif ( ref($err) eq "HASH" && defined $err->{error} and $err->{error} eq "no_email" ) { - $template->{VARS}->{'error_alert'} = "no_email"; - } else { - $template->{VARS}->{'info_alert'} = 1; + if ($@) { + $template->param( error_alert => $@ ); } } } -- 2.39.5