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 1226-1232 ENDSQL Link Here
1226
1226
1227
sub _send_message_by_email {
1227
sub _send_message_by_email {
1228
    my $message = shift or return;
1228
    my $message = shift or return;
1229
    my ($username, $password, $method) = @_;
1229
    my ( $username, $password, $method, $test_mode, $test_email ) = @_;
1230
1230
1231
    my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
1231
    my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
1232
    my $to_address = $message->{'to_address'};
1232
    my $to_address = $message->{'to_address'};
Lines 1282-1296 sub _send_message_by_email { Link Here
1282
1282
1283
    _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
1283
    _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
1284
1284
1285
    if ( sendmail( %sendmail_params ) ) {
1285
    $sendmail_params{to} = $test_email if ( $test_mode && $test_email );
1286
        _set_message_status( { message_id => $message->{'message_id'},
1286
1287
                status     => 'sent' } );
1287
    if ( !$test_mode || ( $test_mode && $test_email ) ) {
1288
        return 1;
1288
        if ( sendmail(%sendmail_params) ) {
1289
    } else {
1289
            _set_message_status(
1290
        _set_message_status( { message_id => $message->{'message_id'},
1290
                {
1291
                status     => 'failed' } );
1291
                    message_id => $message->{'message_id'},
1292
        carp $Mail::Sendmail::error;
1292
                    status     => 'sent'
1293
        return;
1293
                }
1294
            );
1295
            return 1;
1296
        }
1297
        else {
1298
            _set_message_status(
1299
                {
1300
                    message_id => $message->{'message_id'},
1301
                    status     => 'failed'
1302
                }
1303
            );
1304
            carp $Mail::Sendmail::error;
1305
            return;
1306
        }
1294
    }
1307
    }
1295
}
1308
}
1296
1309
Lines 1333-1338 sub _is_duplicate { Link Here
1333
1346
1334
sub _send_message_by_sms {
1347
sub _send_message_by_sms {
1335
    my $message = shift or return;
1348
    my $message = shift or return;
1349
    my $test_mode = shift;
1350
    my $test_sms = shift;
1351
1336
    my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
1352
    my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
1337
1353
1338
    unless ( $member->{smsalertnumber} ) {
1354
    unless ( $member->{smsalertnumber} ) {
Lines 1347-1357 sub _send_message_by_sms { Link Here
1347
        return;
1363
        return;
1348
    }
1364
    }
1349
1365
1350
    my $success = C4::SMS->send_sms( { destination => $member->{'smsalertnumber'},
1366
    my $success;
1351
                                       message     => $message->{'content'},
1367
    if ($test_mode) {
1352
                                     } );
1368
        if ( $test_sms ) {
1353
    _set_message_status( { message_id => $message->{'message_id'},
1369
            $success = C4::SMS->send_sms(
1354
                           status     => ($success ? 'sent' : 'failed') } );
1370
                {
1371
                    destination => $test_sms,
1372
                    message     => $message->{'content'},
1373
                }
1374
            );
1375
        }
1376
    }
1377
    else {
1378
        $success = C4::SMS->send_sms(
1379
            {
1380
                destination => $member->{'smsalertnumber'},
1381
                message     => $message->{'content'},
1382
            }
1383
        );
1384
    }
1385
1386
    _set_message_status(
1387
        {
1388
            message_id => $message->{'message_id'},
1389
            status     => ( $success ? 'sent' : 'failed' )
1390
        }
1391
    );
1392
1355
    return $success;
1393
    return $success;
1356
}
1394
}
1357
1395
(-)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