Bug 12426: [QA Follow-up] Clear to_address to force update
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Mon, 15 Feb 2016 08:13:58 +0000 (09:13 +0100)
committerBrendan A Gallagher <brendan@bywatersolutions.com>
Thu, 3 Mar 2016 20:16:07 +0000 (20:16 +0000)
When resending an email from the Notices tab in Patrons, we would like
to use the recent email address.

Test plan:
[1] Look up a patron with some notices sent.
[2] Adjust the patron email address (watch AutoEmailPrimaryAddress).
[3] Resend the notice. Verify if the new address was used.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com>
C4/Letters.pm

index 5041ddc..0452df2 100644 (file)
@@ -1120,7 +1120,7 @@ sub GetMessage {
   Updates the message to 'pending' status so that
   it will be resent later on.
 
-  returns 1 on success, 0 on failure
+  returns 1 on success, 0 on failure, undef if no message was found
 
 =cut
 
@@ -1130,13 +1130,18 @@ sub ResendMessage {
 
     my $message = GetMessage( $message_id );
     return unless $message;
+    my $rv = 0;
     if ( $message->{status} ne 'pending' ) {
-        return ((C4::Letters::_set_message_status( {
-                    message_id => $message_id,
-                    status => 'pending',
-             } ) > 0) ? 1:0);
+        $rv = C4::Letters::_set_message_status({
+            message_id => $message_id,
+            status => 'pending',
+        });
+        $rv = $rv > 0? 1: 0;
+        # Clear destination email address to force address update
+        _update_message_to_address( $message_id, undef ) if $rv &&
+            $message->{message_transport_type} eq 'email';
     }
-    return 0;
+    return $rv;
 }
 
 =head2 _add_attachements