From c361d265a13ece528da8b838cffd50d0d28ee0f3 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 6 Aug 2025 16:03:28 -0300 Subject: [PATCH] Bug 40608: Continue password change even if notification fails When NotifyPasswordChange is enabled and GetPreparedLetter fails to find a PASSWORD_CHANGE letter template, the set_password method was returning early with undef, preventing the password from being changed. This fixes the issue by: 1. Removing the 'or return;' statement after GetPreparedLetter 2. Wrapping the letter processing in an if block to handle missing templates 3. Ensuring password change continues regardless of notification success The password change should not fail just because the notification cannot be sent. The notification is a nice-to-have feature, but the core functionality (changing the password) should always work. Test plan: 1. Apply the tests patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/Patron.t => FAIL: Tests fail! 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! 5. Verify that when the letter template exists, notifications are still sent 6. Verify that when NotifyPasswordChange is disabled, password changes work 7. Sign off :-D Signed-off-by: Tomas Cohen Arazi --- Koha/Patron.pm | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index cfa570e0f00..b5c9faef43b 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1109,17 +1109,19 @@ sub set_password { 'borrowers' => $self_from_storage->borrowernumber, }, want_librarian => 1, - ) or return; - - my $message_id = C4::Letters::EnqueueLetter( - { - letter => $letter, - borrowernumber => $self_from_storage->id, - to_address => $emailaddr, - message_transport_type => 'email' - } ); - C4::Letters::SendQueuedMessages( { message_id => $message_id } ) if $message_id; + + if ($letter) { + my $message_id = C4::Letters::EnqueueLetter( + { + letter => $letter, + borrowernumber => $self_from_storage->id, + to_address => $emailaddr, + message_transport_type => 'email' + } + ); + C4::Letters::SendQueuedMessages( { message_id => $message_id } ) if $message_id; + } } } } -- 2.50.1