View | Details | Raw Unified | Return to bug 12426
Collapse All | Expand All

(-)a/C4/Letters.pm (-7 / +30 lines)
Lines 1094-1104 sub GetMessageTransportTypes { Link Here
1094
    return $mtts;
1094
    return $mtts;
1095
}
1095
}
1096
1096
1097
=head2 GetMessage
1098
1099
    my $message = C4::Letters::Message($message_id);
1100
1101
=cut
1102
1103
sub GetMessage {
1104
    my ( $message_id ) = @_;
1105
    return unless $message_id;
1106
    my $dbh = C4::Context->dbh;
1107
    return $dbh->selectrow_hashref(q|
1108
        SELECT message_id, borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, to_address, from_address, content_type
1109
        FROM message_queue
1110
        WHERE message_id = ?
1111
    |, {}, $message_id );
1112
}
1113
1097
=head2 ResendMessage
1114
=head2 ResendMessage
1098
1115
1099
  Attempt to resend a message.
1116
  Attempt to resend a message which has failed previously.
1100
1117
1101
  my $message_id = C4::Letters::ResendMessage(123);
1118
  my $has_been_resent = C4::Letters::ResendMessage($message_id);
1102
1119
1103
  Updates the message to 'pending' status so that
1120
  Updates the message to 'pending' status so that
1104
  it will be resent later on.
1121
  it will be resent later on.
Lines 1109-1119 sub GetMessageTransportTypes { Link Here
1109
1126
1110
sub ResendMessage {
1127
sub ResendMessage {
1111
    my $message_id = shift;
1128
    my $message_id = shift;
1112
1129
    return unless $message_id;
1113
    return ((C4::Letters::_set_message_status( {
1130
1114
                message_id => $message_id,
1131
    my $message = GetMessage( $message_id );
1115
                status => 'pending',
1132
    return unless $message;
1116
         } ) > 0) ? 1:0);
1133
    if ( $message->{status} eq 'failed' ) {
1134
        return ((C4::Letters::_set_message_status( {
1135
                    message_id => $message_id,
1136
                    status => 'pending',
1137
             } ) > 0) ? 1:0);
1138
    }
1139
    return 0;
1117
}
1140
}
1118
1141
1119
=head2 _add_attachements
1142
=head2 _add_attachements
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt (-1 / +1 lines)
Lines 71-77 Link Here
71
		<td>
71
		<td>
72
            [% IF ( QUEUED_MESSAGE.status == 'sent' ) %]sent
72
            [% IF ( QUEUED_MESSAGE.status == 'sent' ) %]sent
73
            [% ELSIF ( QUEUED_MESSAGE.status == 'pending' ) %]pending
73
            [% ELSIF ( QUEUED_MESSAGE.status == 'pending' ) %]pending
74
            [% ELSIF ( QUEUED_MESSAGE.status == 'failed' ) %]failed <div class="notice"><a href="/cgi-bin/koha/members/notices.pl?borrowernumber=[% borrowernumber %]&resendnotice=[% QUEUED_MESSAGE.message_id %]" title="Attempt to resend the notice">Resend</a></div>
74
            [% ELSIF ( QUEUED_MESSAGE.status == 'failed' ) %]failed <div class="notice"><a href="/cgi-bin/koha/members/notices.pl?borrowernumber=[% borrowernumber %]&amp;op=resend_notice&amp;message_id=[% QUEUED_MESSAGE.message_id %]" title="Attempt to resend the notice">Resend</a></div>
75
            [% ELSIF ( QUEUED_MESSAGE.status == 'deleted' ) %]deleted
75
            [% ELSIF ( QUEUED_MESSAGE.status == 'deleted' ) %]deleted
76
            [% ELSE %][% QUEUED_MESSAGE.status %][% END %]
76
            [% ELSE %][% QUEUED_MESSAGE.status %][% END %]
77
        </td>
77
        </td>
(-)a/members/notices.pl (-16 / +10 lines)
Lines 49-73 $template->param( $borrower ); Link Here
49
my ($picture, $dberror) = GetPatronImage($borrower->{'borrowernumber'});
49
my ($picture, $dberror) = GetPatronImage($borrower->{'borrowernumber'});
50
$template->param( picture => 1 ) if $picture;
50
$template->param( picture => 1 ) if $picture;
51
51
52
# Getting the messages
52
# Allow resending of messages in Notices tab
53
my $queued_messages = C4::Letters::GetQueuedMessages({borrowernumber => $borrowernumber});
53
my $op = $input->param('op') || q{};
54
54
if ( $op eq 'resend_notice' ) {
55
# Bug 12426 - Allow resending of messages in Notices tab
55
    my $message_id = $input->param('message_id');
56
if ($input->param('resendnotice')) {
56
    my $message = C4::Letters::GetMessage( $message_id );
57
    foreach my $message (@$queued_messages){
57
    if ( $message->{borrowernumber} = $borrowernumber ) {
58
        # resendnotice must be in this borrower's queue - we don't want to make it
58
        C4::Letters::ResendMessage( $message_id );
59
        # possible to change any message just by changing resendnotice id.
60
        if ($message->{message_id} == $input->param('resendnotice')) {
61
            # We also only want to resend messages in failed status
62
            last unless $message->{status} eq "failed";
63
64
            # Modify the message in $queued_message to have its new pending status
65
            $message->{status} = 'pending' if (C4::Letters::ResendMessage($message->{message_id}));
66
            last;
67
        }
68
    }
59
    }
69
}
60
}
70
61
62
# Getting the messages
63
my $queued_messages = C4::Letters::GetQueuedMessages({borrowernumber => $borrowernumber});
64
71
if (C4::Context->preference('ExtendedPatronAttributes')) {
65
if (C4::Context->preference('ExtendedPatronAttributes')) {
72
    my $attributes = GetBorrowerAttributes($borrowernumber);
66
    my $attributes = GetBorrowerAttributes($borrowernumber);
73
    $template->param(
67
    $template->param(
(-)a/t/db_dependent/Letters.t (-5 / +9 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 69;
21
use Test::More tests => 72;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 138-146 is( Link Here
138
);
138
);
139
139
140
# ResendMessage
140
# ResendMessage
141
C4::Letters::ResendMessage($messages->[0]->{message_id});
141
my $resent = C4::Letters::ResendMessage($messages->[0]->{message_id});
142
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
142
my $message = C4::Letters::GetMessage( $messages->[0]->{message_id});
143
is($messages->[0]->{status},'pending', 'ResendMessage sets status to pending correctly (bug 12426)');
143
is( $resent, 1, 'The message should have been resent' );
144
is($message->{status},'pending', 'ResendMessage sets status to pending correctly (bug 12426)');
145
$resent = C4::Letters::ResendMessage($messages->[0]->{message_id});
146
is( $resent, 0, 'The message should not have been resent again' );
147
$resent = C4::Letters::ResendMessage();
148
is( $resent, undef, 'ResendMessage should return undef if not message_id given' );
144
149
145
# GetLetters
150
# GetLetters
146
my $letters = C4::Letters::GetLetters();
151
my $letters = C4::Letters::GetLetters();
147
- 

Return to bug 12426