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

(-)a/C4/Letters.pm (-9 / +32 lines)
Lines 1060-1071 sub GetMessageTransportTypes { Link Here
1060
    return $mtts;
1060
    return $mtts;
1061
}
1061
}
1062
1062
1063
=head2 GetMessage
1064
1065
    my $message = C4::Letters::Message($message_id);
1066
1067
=cut
1068
1069
sub GetMessage {
1070
    my ( $message_id ) = @_;
1071
    return unless $message_id;
1072
    my $dbh = C4::Context->dbh;
1073
    return $dbh->selectrow_hashref(q|
1074
        SELECT message_id, borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, to_address, from_address, content_type
1075
        FROM message_queue
1076
        WHERE message_id = ?
1077
    |, {}, $message_id );
1078
}
1079
1063
=head2 ResendMessage
1080
=head2 ResendMessage
1064
1081
1065
  Attempt to resend a message.
1082
  Attempt to resend a message which has failed previously.
1066
  
1083
1067
  my $message_id = C4::Letters::ResendMessage(123);
1084
  my $has_been_resent = C4::Letters::ResendMessage($message_id);
1068
  
1085
1069
  Updates the message to 'pending' status so that
1086
  Updates the message to 'pending' status so that
1070
  it will be resent later on.
1087
  it will be resent later on.
1071
1088
Lines 1075-1085 sub GetMessageTransportTypes { Link Here
1075
1092
1076
sub ResendMessage {
1093
sub ResendMessage {
1077
    my $message_id = shift;
1094
    my $message_id = shift;
1078
    
1095
    return unless $message_id;
1079
    return ((C4::Letters::_set_message_status( {
1096
1080
                message_id => $message_id,
1097
    my $message = GetMessage( $message_id );
1081
                status => 'pending',
1098
    return unless $message;
1082
         } ) > 0) ? 1:0);
1099
    if ( $message->{status} eq 'failed' ) {
1100
        return ((C4::Letters::_set_message_status( {
1101
                    message_id => $message_id,
1102
                    status => 'pending',
1103
             } ) > 0) ? 1:0);
1104
    }
1105
    return 0;
1083
}
1106
}
1084
1107
1085
=head2 _add_attachements
1108
=head2 _add_attachements
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt (-1 / +1 lines)
Lines 70-76 Link Here
70
		<td>
70
		<td>
71
            [% IF ( QUEUED_MESSAGE.status == 'sent' ) %]sent
71
            [% IF ( QUEUED_MESSAGE.status == 'sent' ) %]sent
72
            [% ELSIF ( QUEUED_MESSAGE.status == 'pending' ) %]pending
72
            [% ELSIF ( QUEUED_MESSAGE.status == 'pending' ) %]pending
73
            [% 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>
73
            [% 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>
74
            [% ELSIF ( QUEUED_MESSAGE.status == 'deleted' ) %]deleted
74
            [% ELSIF ( QUEUED_MESSAGE.status == 'deleted' ) %]deleted
75
            [% ELSE %][% QUEUED_MESSAGE.status %][% END %]
75
            [% ELSE %][% QUEUED_MESSAGE.status %][% END %]
76
        </td>
76
        </td>
(-)a/members/notices.pl (-16 / +11 lines)
Lines 46-74 my ($template, $loggedinuser, $cookie) Link Here
46
				debug => 1,
46
				debug => 1,
47
				});
47
				});
48
48
49
my $op = $input->param('op') || q||;
50
49
$template->param( $borrower );
51
$template->param( $borrower );
50
my ($picture, $dberror) = GetPatronImage($borrower->{'borrowernumber'});
52
my ($picture, $dberror) = GetPatronImage($borrower->{'borrowernumber'});
51
$template->param( picture => 1 ) if $picture;
53
$template->param( picture => 1 ) if $picture;
52
54
53
# Getting the messages
55
# Allow resending of messages in Notices tab
54
my $queued_messages = C4::Letters::GetQueuedMessages({borrowernumber => $borrowernumber});
56
if ( $op eq 'resend_notice' ) {
55
57
    my $message_id = $input->param('message_id');
56
# Bug 12426 - Allow resending of messages in Notices tab
58
    my $message = C4::Letters::GetMessage( $message_id );
57
if ($input->param('resendnotice')) {
59
    if ( $message->{borrowernumber} = $borrowernumber ) {
58
    foreach my $message (@$queued_messages){
60
        C4::Letters::ResendMessage( $message_id );
59
        # resendnotice must be in this borrower's queue - we don't want to make it
60
        # possible to change any message just by changing resendnotice id.
61
        if ($message->{message_id} == $input->param('resendnotice')) {
62
            # We also only want to resend messages in failed status
63
            last unless $message->{status} eq "failed";
64
65
            # Modify the message in $queued_message to have its new pending status
66
            $message->{status} = 'pending' if (C4::Letters::ResendMessage($message->{message_id}));
67
            last;
68
        }
69
    }
61
    }
70
}
62
}
71
63
64
# Getting the messages
65
my $queued_messages = C4::Letters::GetQueuedMessages({borrowernumber => $borrowernumber});
66
72
if (C4::Context->preference('ExtendedPatronAttributes')) {
67
if (C4::Context->preference('ExtendedPatronAttributes')) {
73
    my $attributes = GetBorrowerAttributes($borrowernumber);
68
    my $attributes = GetBorrowerAttributes($borrowernumber);
74
    $template->param(
69
    $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 => 66;
21
use Test::More tests => 69;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 137-145 is( Link Here
137
);
137
);
138
138
139
# ResendMessage
139
# ResendMessage
140
C4::Letters::ResendMessage($messages->[0]->{message_id});
140
my $resent = C4::Letters::ResendMessage($messages->[0]->{message_id});
141
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
141
my $message = C4::Letters::GetMessage( $messages->[0]->{message_id});
142
is($messages->[0]->{status},'pending', 'ResendMessage sets status to pending correctly (bug 12426)');
142
is( $resent, 1, 'The message should have been resent' );
143
is($message->{status},'pending', 'ResendMessage sets status to pending correctly (bug 12426)');
144
$resent = C4::Letters::ResendMessage($messages->[0]->{message_id});
145
is( $resent, 0, 'The message should not have been resent again' );
146
$resent = C4::Letters::ResendMessage();
147
is( $resent, undef, 'ResendMessage should return undef if not message_id given' );
143
148
144
# GetLetters
149
# GetLetters
145
my $letters = C4::Letters::GetLetters();
150
my $letters = C4::Letters::GetLetters();
146
- 

Return to bug 12426