From b514a6172ac2ec2f44c20d24fcbbb3896b7ac19e Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Thu, 3 Sep 2015 14:42:02 +0300 Subject: [PATCH] Bug 12426: Allow resending of messages from the notices tab in the patron account This patch adds a link 'Resend' under a notice in 'failed' status in the Patron's Notices tab. By clicking the link, we will request notices.pl with parameter "resendnotice=XXXXX" where XXXXX is message_id. In notices.pl, we then check whether the given message is actually in 'failed' status. If so, we use the C4::Letters::ResendMessage(123) to change the status of the message into 'pending'. This way it will be processed again by the cronjob process_message_queue.pl. To test, find/create a Patron that has failed notices in message_queue: 1. Enable EnchancedMessagingPreferences system preference 2. Go to Patrons -> Notices 3. In the Notice column, click the title of the failed message 4. Observe that there is nothing for resending the failed message 5. Apply patch. 6. Reload Notices page and repeat step 3 7. Observe that there is now a link "Resend" in the Status-column 8. Click Resend 9. Observe that the message gets into 'pending' status --- C4/Letters.pm | 22 ++++++++++++++++++++++ .../prog/en/modules/members/notices.tt | 4 ++-- members/notices.pl | 16 ++++++++++++++++ t/db_dependent/Letters.t | 7 ++++++- 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index 2e6c4ce..7929506 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -1060,6 +1060,28 @@ sub GetMessageTransportTypes { return $mtts; } +=head2 ResendMessage + + Attempt to resend a message. + + my $message_id = C4::Letters::ResendMessage(123); + + Updates the message to 'pending' status so that + it will be resent later on. + + returns 1 on success, 0 on failure + +=cut + +sub ResendMessage { + my $message_id = shift; + + return ((C4::Letters::_set_message_status( { + message_id => $message_id, + status => 'pending', + } ) > 0) ? 1:0); +} + =head2 _add_attachements named parameters: diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt index 72cb466..d46438e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt @@ -16,7 +16,7 @@ $(".notice").hide(); $(".notice-title").click(function(e){ - $(this).next(".notice").toggle(); + $(this).closest("tr").children().children(".notice").toggle(); e.preventDefault(); }); @@ -70,7 +70,7 @@ [% IF ( QUEUED_MESSAGE.status == 'sent' ) %]sent [% ELSIF ( QUEUED_MESSAGE.status == 'pending' ) %]pending - [% ELSIF ( QUEUED_MESSAGE.status == 'failed' ) %]failed + [% ELSIF ( QUEUED_MESSAGE.status == 'failed' ) %]failed
Resend
[% ELSIF ( QUEUED_MESSAGE.status == 'deleted' ) %]deleted [% ELSE %][% QUEUED_MESSAGE.status %][% END %] diff --git a/members/notices.pl b/members/notices.pl index be1e37c..dc021ed 100755 --- a/members/notices.pl +++ b/members/notices.pl @@ -53,6 +53,22 @@ $template->param( picture => 1 ) if $picture; # Getting the messages my $queued_messages = C4::Letters::GetQueuedMessages({borrowernumber => $borrowernumber}); +# Bug 12426 - Allow resending of messages in Notices tab +if ($input->param('resendnotice')) { + foreach my $message (@$queued_messages){ + # resendnotice must be in this borrower's queue - we don't want to make it + # possible to change any message just by changing resendnotice id. + if ($message->{message_id} == $input->param('resendnotice')) { + # We also only want to resend messages in failed status + last unless $message->{status} eq "failed"; + + # Modify the message in $queued_message to have its new pending status + $message->{status} = 'pending' if (C4::Letters::ResendMessage($message->{message_id})); + last; + } + } +} + if (C4::Context->preference('ExtendedPatronAttributes')) { my $attributes = GetBorrowerAttributes($borrowernumber); $template->param( diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t index cc3242c..49b1320 100644 --- a/t/db_dependent/Letters.t +++ b/t/db_dependent/Letters.t @@ -18,7 +18,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 65; +use Test::More tests => 66; use Test::MockModule; use Test::Warn; @@ -136,6 +136,11 @@ is( 'message marked failed if tried to send SMS message for borrower with no smsalertnumber set (bug 11208)' ); +# ResendMessage +C4::Letters::ResendMessage($messages->[0]->{message_id}); +$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber }); +is($messages->[0]->{status},'pending', 'ResendMessage sets status to pending correctly (bug 12426)'); + # GetLetters my $letters = C4::Letters::GetLetters(); is( @$letters, 0, 'GetLetters returns the correct number of letters' ); -- 1.9.1