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

(-)a/C4/Letters.pm (-10 / +30 lines)
Lines 1004-1010 sub GetQueuedMessages { Link Here
1004
1004
1005
    my $dbh = C4::Context->dbh();
1005
    my $dbh = C4::Context->dbh();
1006
    my $statement = << 'ENDSQL';
1006
    my $statement = << 'ENDSQL';
1007
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued
1007
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued, delivery_note
1008
FROM message_queue
1008
FROM message_queue
1009
ENDSQL
1009
ENDSQL
1010
1010
Lines 1137-1143 sub _send_message_by_email { Link Here
1137
        unless ($member) {
1137
        unless ($member) {
1138
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1138
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1139
            _set_message_status( { message_id => $message->{'message_id'},
1139
            _set_message_status( { message_id => $message->{'message_id'},
1140
                                   status     => 'failed' } );
1140
                                   status     => 'failed',
1141
                                   delivery_note => 'Invalid borrowernumber '.$message->{borrowernumber} } );
1141
            return;
1142
            return;
1142
        }
1143
        }
1143
        $to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} );
1144
        $to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} );
Lines 1145-1151 sub _send_message_by_email { Link Here
1145
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1146
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1146
            # warning too verbose for this more common case?
1147
            # warning too verbose for this more common case?
1147
            _set_message_status( { message_id => $message->{'message_id'},
1148
            _set_message_status( { message_id => $message->{'message_id'},
1148
                                   status     => 'failed' } );
1149
                                   status     => 'failed',
1150
                                   delivery_note => 'Unable to find an email address for this borrower' } );
1149
            return;
1151
            return;
1150
        }
1152
        }
1151
    }
1153
    }
Lines 1186-1196 sub _send_message_by_email { Link Here
1186
    _update_message_to_address($message->{'message_id'},$to_address) unless $message->{to_address}; #if initial message address was empty, coming here means that a to address was found and queue should be updated
1188
    _update_message_to_address($message->{'message_id'},$to_address) unless $message->{to_address}; #if initial message address was empty, coming here means that a to address was found and queue should be updated
1187
    if ( sendmail( %sendmail_params ) ) {
1189
    if ( sendmail( %sendmail_params ) ) {
1188
        _set_message_status( { message_id => $message->{'message_id'},
1190
        _set_message_status( { message_id => $message->{'message_id'},
1189
                status     => 'sent' } );
1191
                status     => 'sent',
1192
                delivery_note => '' } );
1190
        return 1;
1193
        return 1;
1191
    } else {
1194
    } else {
1192
        _set_message_status( { message_id => $message->{'message_id'},
1195
        _set_message_status( { message_id => $message->{'message_id'},
1193
                status     => 'failed' } );
1196
                status     => 'failed',
1197
                delivery_note => $Mail::Sendmail::error } );
1194
        carp $Mail::Sendmail::error;
1198
        carp $Mail::Sendmail::error;
1195
        return;
1199
        return;
1196
    }
1200
    }
Lines 1239-1259 sub _send_message_by_sms { Link Here
1239
1243
1240
    unless ( $member->{smsalertnumber} ) {
1244
    unless ( $member->{smsalertnumber} ) {
1241
        _set_message_status( { message_id => $message->{'message_id'},
1245
        _set_message_status( { message_id => $message->{'message_id'},
1242
                               status     => 'failed' } );
1246
                               status     => 'failed',
1247
                               delivery_note => 'Missing SMS number' } );
1243
        return;
1248
        return;
1244
    }
1249
    }
1245
1250
1246
    if ( _is_duplicate( $message ) ) {
1251
    if ( _is_duplicate( $message ) ) {
1247
        _set_message_status( { message_id => $message->{'message_id'},
1252
        _set_message_status( { message_id => $message->{'message_id'},
1248
                               status     => 'failed' } );
1253
                               status     => 'failed',
1254
                               delivery_note => 'Message is duplicate' } );
1249
        return;
1255
        return;
1250
    }
1256
    }
1251
1257
1252
    my $success = C4::SMS->send_sms( { destination => $member->{'smsalertnumber'},
1258
    my $success = C4::SMS->send_sms( { destination => $member->{'smsalertnumber'},
1253
                                       message     => $message->{'content'},
1259
                                       message     => $message->{'content'},
1260
                                       message_id  => $message->{'message_id'}
1254
                                     } );
1261
                                     } );
1255
    _set_message_status( { message_id => $message->{'message_id'},
1262
    
1256
                           status     => ($success ? 'sent' : 'failed') } );
1263
    # Some SMS::Send drivers return a hash with delivery note, and some only
1264
    # success value. Let's add an appropriate delivery note if driver returns
1265
    # us one.
1266
    if (ref($success) eq 'HASH') {
1267
        _set_message_status( { message_id => $message->{'message_id'},
1268
                           status     => ($success->{status} ? 'sent' : 'failed'),
1269
                           delivery_note => $success->{delivery_note} } );
1270
    } else {
1271
        _set_message_status( { message_id => $message->{'message_id'},
1272
                           status     => ($success ? 'sent' : 'failed'),
1273
                           delivery_note => ($success ? '' : 'No notes from SMS driver') } );
1274
    }
1275
  
1257
    return $success;
1276
    return $success;
1258
}
1277
}
1259
1278
Lines 1271-1279 sub _set_message_status { Link Here
1271
    }
1290
    }
1272
1291
1273
    my $dbh = C4::Context->dbh();
1292
    my $dbh = C4::Context->dbh();
1274
    my $statement = 'UPDATE message_queue SET status= ? WHERE message_id = ?';
1293
    my $statement = 'UPDATE message_queue SET status= ?, delivery_note= ? WHERE message_id = ?';
1275
    my $sth = $dbh->prepare( $statement );
1294
    my $sth = $dbh->prepare( $statement );
1276
    my $result = $sth->execute( $params->{'status'},
1295
    my $result = $sth->execute( $params->{'status'},
1296
                                $params->{'delivery_note'},
1277
                                $params->{'message_id'} );
1297
                                $params->{'message_id'} );
1278
    return $result;
1298
    return $result;
1279
}
1299
}
(-)a/installer/data/mysql/atomicupdate/Bug-14723_-_Additional_delivery_notes_to_messages.pl (+8 lines)
Line 0 Link Here
1
#! /usr/bin/perl
2
use strict;
3
use warnings;
4
use C4::Context;
5
my $dbh = C4::Context->dbh;
6
7
$dbh->do("ALTER TABLE message_queue ADD delivery_note TEXT");
8
print "Upgrade to done (Bug 14723 - Additional delivery notes to messages)\n";
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt (-1 / +5 lines)
Lines 49-55 Link Here
49
		<th>Type</th>
49
		<th>Type</th>
50
		<th>Status</th>
50
		<th>Status</th>
51
		<th>Time</th>
51
		<th>Time</th>
52
	    </tr>
52
	        <th>Delivery note</th>
53
            </tr>
53
	</thead>
54
	</thead>
54
	<tbody>
55
	<tbody>
55
	    [% FOREACH QUEUED_MESSAGE IN QUEUED_MESSAGES %]
56
	    [% FOREACH QUEUED_MESSAGE IN QUEUED_MESSAGES %]
Lines 75-80 Link Here
75
            [% ELSE %][% QUEUED_MESSAGE.status %][% END %]
76
            [% ELSE %][% QUEUED_MESSAGE.status %][% END %]
76
        </td>
77
        </td>
77
        <td><span title="[% QUEUED_MESSAGE.time_queued %]">[% QUEUED_MESSAGE.time_queued | $KohaDates with_hours => 1 %]</span></td>
78
        <td><span title="[% QUEUED_MESSAGE.time_queued %]">[% QUEUED_MESSAGE.time_queued | $KohaDates with_hours => 1 %]</span></td>
79
                <td>
80
            [% QUEUED_MESSAGE.delivery_note %]
81
        </td>
78
	    </tr>
82
	    </tr>
79
	    [% END %]
83
	    [% END %]
80
	</tbody>
84
	</tbody>
(-)a/t/db_dependent/MessageDeliveryNote.t (-1 / +111 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/env perl
2
3
# Copyright 2015 Open Source Freedom Fighters
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
$ENV{KOHA_PAGEOBJECT_DEBUG} = 1;
20
use Modern::Perl;
21
22
use Test::More;
23
use Try::Tiny; #Even Selenium::Remote::Driver uses Try::Tiny :)
24
25
use Koha::Auth::PermissionManager;
26
27
use t::lib::Page::Mainpage;
28
use t::lib::Page::Opac::OpacMain;
29
use t::lib::Page::Opac::OpacMemberentry;
30
use t::lib::Page::Members::Memberentry;
31
use t::lib::Page::Members::Moremember;
32
use t::lib::Page::Members::Notices;
33
34
use t::lib::TestObjects::BorrowerFactory;
35
use t::lib::TestObjects::MessageQueueFactory;
36
37
##Setting up the test context
38
my $testContext = {};
39
40
my $password = '1234';
41
my $borrowerFactory = t::lib::TestObjects::BorrowerFactory->new();
42
my $borrowers = $borrowerFactory->createTestGroup([
43
            {firstname  => 'Testthree',
44
             surname    => 'Testfour',
45
             cardnumber => 'superuberadmin',
46
             branchcode => 'CPL',
47
             userid     => 'god',
48
             address    => 'testi',
49
             city       => 'joensuu',
50
             zipcode    => '80100',
51
             password   => $password,
52
            },
53
        ], undef, $testContext);
54
my $messages = t::lib::TestObjects::MessageQueueFactory->createTestGroup([
55
            {letter => {
56
                title => "Test title",
57
                content => "Tessst content",
58
                },
59
             cardnumber => $borrowers->{'superuberadmin'}->cardnumber,
60
             message_transport_type => 'sms',
61
             message_id => '123',
62
            },
63
        ], undef, $testContext);
64
    
65
my $permissionManager = Koha::Auth::PermissionManager->new();
66
$permissionManager->grantPermissions($borrowers->{'superuberadmin'}, {superlibrarian => 'superlibrarian'});
67
68
eval {
69
70
    # staff client
71
    my $notices = t::lib::Page::Members::Notices->new({borrowernumber => $borrowers->{'superuberadmin'}->borrowernumber, op => 'modify', destination => 'circ', categorycode => 'PT'});
72
73
    # login and check that our table is displayed correctly
74
    $notices->doPasswordLogin($borrowers->{'superuberadmin'}->userid(), $password)->
75
    hasDeliveryNoteColumnInNoticesTable()->
76
    hasTextInTableCell(""); # exactly one should be empty (delivery note)
77
    
78
    # let's send the message
79
    C4::Letters::SendQueuedMessages({ username => "test", password=> "lol" });
80
    
81
    # message sending should fail, lets check it. refresh page first
82
    $notices->navigateToNotices()->
83
    hasTextInTableCell("failed")->
84
    hasTextInTableCell("Missing SMS number");
85
    
86
};
87
if ($@) { #Catch all leaking errors and gracefully terminate.
88
    warn $@;
89
    tearDown();
90
    exit 1;
91
}
92
93
##All tests done, tear down test context
94
tearDown();
95
done_testing;
96
97
sub tearDown {
98
    t::lib::TestObjects::ObjectFactory->tearDownTestContext($testContext);
99
}
100
101
102
103
104
105
106
107
108
######################################################
109
    ###  STARTING TEST IMPLEMENTATIONS         ###
110
######################################################
111

Return to bug 14723