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

(-)a/C4/Letters.pm (-17 / +55 lines)
Lines 989-997 sub SendQueuedMessages { Link Here
989
                my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
989
                my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
990
                my $sms_provider = Koha::SMS::Providers->find( $member->{'sms_provider_id'} );
990
                my $sms_provider = Koha::SMS::Providers->find( $member->{'sms_provider_id'} );
991
                $message->{to_address} .= '@' . $sms_provider->domain();
991
                $message->{to_address} .= '@' . $sms_provider->domain();
992
                _send_message_by_email( $message, $params->{'username'}, $params->{'password'}, $params->{'method'} );
992
                _send_message_by_email( $message, $params->{'username'}, $params->{'password'}, $params->{'method'}, $params->('test_mode'), $params->{'test_email'} );
993
            } else {
993
            } else {
994
                _send_message_by_sms( $message );
994
                _send_message_by_sms( $message, $params->{'test_mode'}, $params->{test_sms} );
995
            }
995
            }
996
        }
996
        }
997
    }
997
    }
Lines 1176-1182 ENDSQL Link Here
1176
1176
1177
sub _send_message_by_email {
1177
sub _send_message_by_email {
1178
    my $message = shift or return;
1178
    my $message = shift or return;
1179
    my ($username, $password, $method) = @_;
1179
    my ( $username, $password, $method, $test_mode, $test_email ) = @_;
1180
1180
1181
    my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
1181
    my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
1182
    my $to_address = $message->{'to_address'};
1182
    my $to_address = $message->{'to_address'};
Lines 1232-1246 sub _send_message_by_email { Link Here
1232
1232
1233
    _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
1233
    _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
1234
1234
1235
    if ( sendmail( %sendmail_params ) ) {
1235
    $sendmail_params{to} = $test_email if ( $test_mode && $test_email )
1236
        _set_message_status( { message_id => $message->{'message_id'},
1236
1237
                status     => 'sent' } );
1237
    if ( !$test_mode || ( $test_mode && $test_email ) ) {
1238
        return 1;
1238
        if ( sendmail(%sendmail_params) ) {
1239
    } else {
1239
            _set_message_status(
1240
        _set_message_status( { message_id => $message->{'message_id'},
1240
                {
1241
                status     => 'failed' } );
1241
                    message_id => $message->{'message_id'},
1242
        carp $Mail::Sendmail::error;
1242
                    status     => 'sent'
1243
        return;
1243
                }
1244
            );
1245
            return 1;
1246
        }
1247
        else {
1248
            _set_message_status(
1249
                {
1250
                    message_id => $message->{'message_id'},
1251
                    status     => 'failed'
1252
                }
1253
            );
1254
            carp $Mail::Sendmail::error;
1255
            return;
1256
        }
1244
    }
1257
    }
1245
}
1258
}
1246
1259
Lines 1283-1288 sub _is_duplicate { Link Here
1283
1296
1284
sub _send_message_by_sms {
1297
sub _send_message_by_sms {
1285
    my $message = shift or return;
1298
    my $message = shift or return;
1299
    my $test_mode = shift;
1300
    my $test_sms = shift;
1301
1286
    my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
1302
    my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
1287
1303
1288
    unless ( $member->{smsalertnumber} ) {
1304
    unless ( $member->{smsalertnumber} ) {
Lines 1297-1307 sub _send_message_by_sms { Link Here
1297
        return;
1313
        return;
1298
    }
1314
    }
1299
1315
1300
    my $success = C4::SMS->send_sms( { destination => $member->{'smsalertnumber'},
1316
    my $success;
1301
                                       message     => $message->{'content'},
1317
    if ($test_mode) {
1302
                                     } );
1318
        if ( $test_sms ) {
1303
    _set_message_status( { message_id => $message->{'message_id'},
1319
            $success = C4::SMS->send_sms(
1304
                           status     => ($success ? 'sent' : 'failed') } );
1320
                {
1321
                    destination => $test_sms,
1322
                    message     => $message->{'content'},
1323
                }
1324
            );
1325
        }
1326
    }
1327
    else {
1328
        $success = C4::SMS->send_sms(
1329
            {
1330
                destination => $member->{'smsalertnumber'},
1331
                message     => $message->{'content'},
1332
            }
1333
        );
1334
    }
1335
1336
    _set_message_status(
1337
        {
1338
            message_id => $message->{'message_id'},
1339
            status     => ( $success ? 'sent' : 'failed' )
1340
        }
1341
    );
1342
1305
    return $success;
1343
    return $success;
1306
}
1344
}
1307
1345
(-)a/misc/cronjobs/process_message_queue.pl (-7 / +17 lines)
Lines 34-39 my $password = undef; Link Here
34
my $method = 'LOGIN';
34
my $method = 'LOGIN';
35
my $help = 0;
35
my $help = 0;
36
my $verbose = 0;
36
my $verbose = 0;
37
my $test;
38
my $test_email;
39
my $test_sms;
37
40
38
GetOptions(
41
GetOptions(
39
    'u|username:s'      => \$username,
42
    'u|username:s'      => \$username,
Lines 41-46 GetOptions( Link Here
41
    'm|method:s'        => \$method,
44
    'm|method:s'        => \$method,
42
    'h|help|?'          => \$help,
45
    'h|help|?'          => \$help,
43
    'v|verbose'         => \$verbose,
46
    'v|verbose'         => \$verbose,
47
    't|test'            => \$test,
48
    'e|test-email'      => \$test_email,
49
    's|test-sms'        => \$test_sms,
44
);
50
);
45
my $usage = << 'ENDUSAGE';
51
my $usage = << 'ENDUSAGE';
46
52
Lines 51-61 you run this regularly from cron, especially if you are using the Link Here
51
advance_notices.pl script.
57
advance_notices.pl script.
52
58
53
This script has the following parameters :
59
This script has the following parameters :
54
    -u --username: username of mail account
60
    -u --username   : username of mail account
55
    -p --password: password of mail account
61
    -p --password   : password of mail account
56
    -m --method: authentication method required by SMTP server (See perldoc Sendmail.pm for supported authentication types.)
62
    -m --method     : authentication method required by SMTP server (See perldoc Sendmail.pm for supported authentication types.)
57
    -h --help: this message
63
    -h --help       : this message
58
    -v --verbose: provides verbose output to STDOUT
64
    -v --verbose    : provides verbose output to STDOUT
65
    -t --test-mode  : Enables test mode where all messages are redirected or supressed
66
    -e --test-email : Email address for test mode. All emails will be sent to this address instead of the patron's email address.
67
                      If test mode is set but test email is not, emails will not actually be sent
68
    -s --test-sms   : SMS number for test mode. All SMS messages will be sent to this number instead of the patron's sms number.
69
                      If test mode is set but test SMS is not, SMS messages will not actually be sent
59
70
60
ENDUSAGE
71
ENDUSAGE
61
72
Lines 63-67 die $usage if $help; Link Here
63
74
64
cronlogaction();
75
cronlogaction();
65
76
66
C4::Letters::SendQueuedMessages( { verbose => $verbose, username => $username, password => $password, method => $method } );
77
C4::Letters::SendQueuedMessages( { verbose => $verbose, username => $username, password => $password, method => $method, test_mode => $test, test_email => $test_email, test_sms => $test_sms } );
67
78
68
- 

Return to bug 15857