From df835c5df6e5d1af0fb434f21e1e15b9d5736c10 Mon Sep 17 00:00:00 2001 From: Mark Gavillet Date: Wed, 7 Mar 2018 10:18:24 +0000 Subject: [PATCH] Bug 18570 - Password recovery e-mail only sent after message queue is processed Adds a new subroutine to C4/Letters.pm which sends the password reset email to the borrower through the message queue immediately. To test, set the syspref "OpacResetPassword" to "allowed", create a patron with an email address in their record, then click the "Forgotten password" link on the login screen. The new subroutine will match on borrowernumber and letter_code='PASSWORD_RESET' in the message queue and process the single entry, marking it as sent. If your mail server is not enabled, check the mail server logs to see the attempted send (e.g. /var/log/exim4/mainlog) --- C4/Letters.pm | 29 +++++++++++++++++++++++++++-- Koha/Patron/Password/Recovery.pm | 2 ++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index ada27943b0..6bb909aad7 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -1072,6 +1072,27 @@ sub SendQueuedMessages { return scalar( @$unsent_messages ); } +=head2 SendPasswordEmailFromQueue ($borrowernumber) + + my $sent_pw = SendPasswordEmailFromQueue($borrowernumber) + +Used to immediately send a forgotten password request rather than have the user wait until the next time the entire queue is processed. +Messages from the `message_queue` table are matched on borrowernumber and letter_code='PASSWORD_RESET' + +=cut + +sub SendPasswordEmailFromQueue { + my $borrowernumber = shift; + + my $pw_msg = _get_unsent_messages( { borrowernumber => $borrowernumber, + letter_code => 'PASSWORD_RESET' } ); + if ( $pw_msg ) { + _send_message_by_email( $pw_msg->[0], undef, undef, 'LOGIN' ); + } else { + return 0; + } +} + =head2 GetRSSMessages my $message_list = GetRSSMessages( { limit => 10, borrowernumber => '14' } ) @@ -1278,17 +1299,21 @@ ENDSQL my @query_params = ('pending'); if ( ref $params ) { if ( $params->{'message_transport_type'} ) { - $statement .= ' AND message_transport_type = ? '; + $statement .= ' AND mq.message_transport_type = ? '; push @query_params, $params->{'message_transport_type'}; } if ( $params->{'borrowernumber'} ) { - $statement .= ' AND borrowernumber = ? '; + $statement .= ' AND mq.borrowernumber = ? '; push @query_params, $params->{'borrowernumber'}; } if ( $params->{'limit'} ) { $statement .= ' limit ? '; push @query_params, $params->{'limit'}; } + if ( $params->{'letter_code'} ) { + $statement .= ' AND mq.letter_code = ? '; + push @query_params, $params->{'letter_code'}; + } } $debug and warn "_get_unsent_messages SQL: $statement"; diff --git a/Koha/Patron/Password/Recovery.pm b/Koha/Patron/Password/Recovery.pm index a23a609b90..154bcd4a8e 100644 --- a/Koha/Patron/Password/Recovery.pm +++ b/Koha/Patron/Password/Recovery.pm @@ -161,6 +161,8 @@ sub SendPasswordRecoveryEmail { } ); + my $sent_pw = C4::Letters::SendPasswordEmailFromQueue($borrower->borrowernumber); + return 1; } -- 2.14.3 (Apple Git-98)