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

(-)a/C4/Letters.pm (-2 / +2 lines)
Lines 1598-1604 sub _send_message_by_sms { Link Here
1598
        return;
1598
        return;
1599
    }
1599
    }
1600
1600
1601
    my $success = C4::SMS->send_sms(
1601
    my ( $success, $error ) = C4::SMS->send_sms(
1602
        {
1602
        {
1603
            destination => $patron->smsalertnumber,
1603
            destination => $patron->smsalertnumber,
1604
            message     => $message->{'content'},
1604
            message     => $message->{'content'},
Lines 1619-1625 sub _send_message_by_sms { Link Here
1619
            {
1619
            {
1620
                message_id   => $message->{'message_id'},
1620
                message_id   => $message->{'message_id'},
1621
                status       => 'failed',
1621
                status       => 'failed',
1622
                failure_code => 'NO_NOTES'
1622
                failure_code => $error || 'NO_NOTES',
1623
            }
1623
            }
1624
        );
1624
        );
1625
    }
1625
    }
(-)a/C4/SMS.pm (-4 / +8 lines)
Lines 25-32 C4::SMS - send SMS messages Link Here
25
25
26
=head1 SYNOPSIS
26
=head1 SYNOPSIS
27
27
28
my $success = C4::SMS->send_sms({ message     => 'This is my text message',
28
my ( $success, $error ) = C4::SMS->send_sms(
29
                                  destination => '212-555-1212' });
29
    {
30
        message     => 'This is my text message',
31
        destination => '212-555-1212'
32
    }
33
);
30
34
31
=head1 DESCRIPTION
35
=head1 DESCRIPTION
32
36
Lines 87-93 sub send_sms { Link Here
87
91
88
    # This allows the user to override the driver. See SMS::Send::Test
92
    # This allows the user to override the driver. See SMS::Send::Test
89
    my $driver = exists $params->{'driver'} ? $params->{'driver'} : $self->driver();
93
    my $driver = exists $params->{'driver'} ? $params->{'driver'} : $self->driver();
90
    return unless $driver;
94
    return ( undef, 'SMS_SEND_DRIVER_MISSING' ) unless $driver;
91
95
92
    my ($sent, $sender);
96
    my ($sent, $sender);
93
97
Lines 127-133 sub send_sms { Link Here
127
    #Catch those errors and fail the sms-sending gracefully.
131
    #Catch those errors and fail the sms-sending gracefully.
128
    if ($@) {
132
    if ($@) {
129
        warn $@;
133
        warn $@;
130
        return;
134
        return ( undef, $@ );
131
    }
135
    }
132
    # warn 'failure' unless $sent;
136
    # warn 'failure' unless $sent;
133
    return $sent;
137
    return $sent;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt (-1 / +3 lines)
Lines 108-116 Link Here
108
                                                    [% ELSIF ( QUEUED_MESSAGE.failure_code == 'MISSING_SMS' ) %]<span class="clearfix">Missing SMS number</span>
108
                                                    [% ELSIF ( QUEUED_MESSAGE.failure_code == 'MISSING_SMS' ) %]<span class="clearfix">Missing SMS number</span>
109
                                                    [% ELSIF ( QUEUED_MESSAGE.failure_code == 'DUPLICATE_MESSAGE' ) %]<span class="clearfix">Message is duplicate</span>
109
                                                    [% ELSIF ( QUEUED_MESSAGE.failure_code == 'DUPLICATE_MESSAGE' ) %]<span class="clearfix">Message is duplicate</span>
110
                                                    [% ELSIF ( QUEUED_MESSAGE.failure_code == 'NO_NOTES' ) %]<span class="clearfix">No notes from SMS driver</span>
110
                                                    [% ELSIF ( QUEUED_MESSAGE.failure_code == 'NO_NOTES' ) %]<span class="clearfix">No notes from SMS driver</span>
111
                                                    [% ELSIF ( QUEUED_MESSAGE.failure_code == 'SMS_SEND_DRIVER_MISSING' ) %]<span class="clearfix">The SMS driver could not be loaded</span>
111
                                                    [% ELSIF ( QUEUED_MESSAGE.failure_code == 'SENDMAIL' ) %]<span class="clearfix">Unhandled email failure, check the logs for further details</span>
112
                                                    [% ELSIF ( QUEUED_MESSAGE.failure_code == 'SENDMAIL' ) %]<span class="clearfix">Unhandled email failure, check the logs for further details</span>
112
                                                    [% ELSIF ( QUEUED_MESSAGE.failure_code == "UNKNOWN_ERROR" ) %]<span class="clearfix">Unknown error</span>
113
                                                    [% ELSIF ( QUEUED_MESSAGE.failure_code == "UNKNOWN_ERROR" ) %]<span class="clearfix">Unknown error</span>
113
                                                    [% ELSE %]<span class="clearfix">Error occurred while sending email</span>
114
                                                    [% ELSE %]
115
                                                        <span class="clearfix">Message failed to send with the following error: [% QUEUED_MESSAGE.failure_code | html %]</span>
114
                                                    [% END %]
116
                                                    [% END %]
115
                                                [% END %]
117
                                                [% END %]
116
                                                [% IF ( QUEUED_MESSAGE.status == 'sent' ) %]
118
                                                [% IF ( QUEUED_MESSAGE.status == 'sent' ) %]
(-)a/t/SMS.t (-26 / +33 lines)
Lines 19-62 use Modern::Perl; Link Here
19
19
20
use t::lib::Mocks;
20
use t::lib::Mocks;
21
21
22
use Test::More tests => 7;
22
use Test::More tests => 8;
23
23
24
BEGIN {
24
BEGIN {
25
    use_ok('C4::SMS', qw( driver send_sms ));
25
    use_ok( 'C4::SMS', qw( driver send_sms ) );
26
}
26
}
27
27
28
29
my $driver = 'my mock driver';
28
my $driver = 'my mock driver';
30
t::lib::Mocks::mock_preference('SMSSendDriver', $driver);
29
t::lib::Mocks::mock_preference( 'SMSSendDriver', $driver );
31
is( C4::SMS->driver(), $driver, 'driver returns the SMSSendDriver correctly' );
30
is( C4::SMS->driver(), $driver, 'driver returns the SMSSendDriver correctly' );
32
31
33
t::lib::Mocks::mock_preference('SMSSendUsername', 'username');
32
t::lib::Mocks::mock_preference( 'SMSSendUsername', 'username' );
34
t::lib::Mocks::mock_preference('SMSSendPassword', 'pwd');
33
t::lib::Mocks::mock_preference( 'SMSSendPassword', 'pwd' );
35
34
36
my $send_sms = C4::SMS->send_sms();
35
my ( $send_sms, $error ) = C4::SMS->send_sms();
37
is( $send_sms, undef, 'send_sms without arguments returns undef' );
36
is( $send_sms, undef, 'send_sms without arguments returns undef' );
38
37
39
$send_sms = C4::SMS->send_sms({
38
($send_sms) = C4::SMS->send_sms(
40
    destination => 'my destination',
39
    {
41
});
40
        destination => 'my destination',
41
    }
42
);
42
is( $send_sms, undef, 'send_sms without message returns undef' );
43
is( $send_sms, undef, 'send_sms without message returns undef' );
43
44
44
$send_sms = C4::SMS->send_sms({
45
($send_sms) = C4::SMS->send_sms(
45
    message => 'my message',
46
    {
46
});
47
        message => 'my message',
48
    }
49
);
47
is( $send_sms, undef, 'send_sms without destination returns undef' );
50
is( $send_sms, undef, 'send_sms without destination returns undef' );
48
51
49
$send_sms = C4::SMS->send_sms({
52
( $send_sms, $error ) = C4::SMS->send_sms(
50
    destination => 'my destination',
53
    {
51
    message => 'my message',
54
        destination => 'my destination',
52
    driver => '',
55
        message     => 'my message',
53
});
56
        driver      => '',
54
is( $send_sms, undef, 'send_sms with an undef driver returns undef' );
57
    }
55
58
);
56
$send_sms = C4::SMS->send_sms({
59
is( $send_sms, undef,                     'send_sms with an undef driver returns undef' );
57
    destination => '+33123456789',
60
is( $error,    'SMS_SEND_DRIVER_MISSING', 'Error code returned is SMS_SEND_DRIVER_MISSING' );
58
    message => 'my message',
61
59
    driver => 'Test',
62
( $send_sms, $error ) = C4::SMS->send_sms(
60
});
63
    {
64
        destination => '+33123456789',
65
        message     => 'my message',
66
        driver      => 'Test',
67
    }
68
);
61
is( $send_sms, 1, 'send_sms returns 1' );
69
is( $send_sms, 1, 'send_sms returns 1' );
62
70
63
- 

Return to bug 36307