From f2106cc732fd085f33ac3b25be3610ff8ccfe0c6 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Thu, 8 Mar 2018 00:15:33 +0000 Subject: [PATCH] Bug 18570: Send Password Reset Emails immediately Run through the password reset process, and your server should send the message immediate, not waiting for the cronjob. Signed-off-by: Josef Moravec Signed-off-by: Julian Maurice Signed-off-by: Jonathan Druart Signed-off-by: Nick Clemens --- C4/Letters.pm | 15 ++++++++++++--- Koha/Patron/Password/Recovery.pm | 7 +++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index acf4b65717..251493f32d 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -1035,7 +1035,12 @@ Returns number of messages sent. sub SendQueuedMessages { my $params = shift; - my $unsent_messages = _get_unsent_messages( { limit => $params->{limit} } ); + my $which_unsent_messages = { + 'limit' => $params->{'limit'} // 0, + 'borrowernumber' => $params->{'borrowernumber'} // q{}, + 'letter_code' => $params->{'letter_code'} // q{}, + }; + my $unsent_messages = _get_unsent_messages( $which_unsent_messages ); MESSAGE: foreach my $message ( @$unsent_messages ) { # warn Data::Dumper->Dump( [ $message ], [ 'message' ] ); warn sprintf( 'sending %s message to patron: %s', @@ -1279,13 +1284,17 @@ sub _get_unsent_messages { 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->{'letter_code'} ) { + $statement .= ' AND mq.letter_code = ? '; + push @query_params, $params->{'letter_code'}; + } if ( $params->{'limit'} ) { $statement .= ' limit ? '; push @query_params, $params->{'limit'}; diff --git a/Koha/Patron/Password/Recovery.pm b/Koha/Patron/Password/Recovery.pm index 5a352fb25c..0d09923bf1 100644 --- a/Koha/Patron/Password/Recovery.pm +++ b/Koha/Patron/Password/Recovery.pm @@ -161,8 +161,11 @@ sub SendPasswordRecoveryEmail { message_transport_type => 'email', } ); - - return 1; + my $num_letters_attempted = C4::Letters::SendQueuedMessages( { + borrowernumber => $borrower->borrowernumber, + letter_code => 'PASSWORD_RESET' + } ); + return ($num_letters_attempted > 0); } =head2 CompletePasswordRecovery -- 2.39.5