From 70941cde0ec70c4f59ff51abd713594a92cf1e3f 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 --- 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 219779bc3e..841362a169 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -1038,7 +1038,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', @@ -1282,13 +1287,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