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

(-)a/C4/Letters.pm (-7 / +30 lines)
Lines 1085-1095 sub GetMessageTransportTypes { Link Here
1085
    return $mtts;
1085
    return $mtts;
1086
}
1086
}
1087
1087
1088
=head2 GetMessage
1089
1090
    my $message = C4::Letters::Message($message_id);
1091
1092
=cut
1093
1094
sub GetMessage {
1095
    my ( $message_id ) = @_;
1096
    return unless $message_id;
1097
    my $dbh = C4::Context->dbh;
1098
    return $dbh->selectrow_hashref(q|
1099
        SELECT message_id, borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, to_address, from_address, content_type
1100
        FROM message_queue
1101
        WHERE message_id = ?
1102
    |, {}, $message_id );
1103
}
1104
1088
=head2 ResendMessage
1105
=head2 ResendMessage
1089
1106
1090
  Attempt to resend a message.
1107
  Attempt to resend a message which has failed previously.
1091
1108
1092
  my $message_id = C4::Letters::ResendMessage(123);
1109
  my $has_been_resent = C4::Letters::ResendMessage($message_id);
1093
1110
1094
  Updates the message to 'pending' status so that
1111
  Updates the message to 'pending' status so that
1095
  it will be resent later on.
1112
  it will be resent later on.
Lines 1100-1110 sub GetMessageTransportTypes { Link Here
1100
1117
1101
sub ResendMessage {
1118
sub ResendMessage {
1102
    my $message_id = shift;
1119
    my $message_id = shift;
1103
1120
    return unless $message_id;
1104
    return ((C4::Letters::_set_message_status( {
1121
1105
                message_id => $message_id,
1122
    my $message = GetMessage( $message_id );
1106
                status => 'pending',
1123
    return unless $message;
1107
         } ) > 0) ? 1:0);
1124
    if ( $message->{status} eq 'failed' ) {
1125
        return ((C4::Letters::_set_message_status( {
1126
                    message_id => $message_id,
1127
                    status => 'pending',
1128
             } ) > 0) ? 1:0);
1129
    }
1130
    return 0;
1108
}
1131
}
1109
1132
1110
=head2 _add_attachements
1133
=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 => 70;
21
use Test::More tests => 73;
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