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

(-)a/C4/Letters.pm (+6 lines)
Lines 952-957 sub EnqueueLetter { Link Here
952
        );
952
        );
953
    }
953
    }
954
954
955
    if ($params->{message_transport_type} eq 'sms') {
956
        my $limit = C4::Context->preference('SMSSendMaxChar');
957
        $params->{letter}->{content} = substr($params->{letter}->{content}, 0, $limit - 3) . '...'
958
            if ($limit && length($params->{letter}->{content}) > $limit);
959
    }
960
955
    my $message = Koha::Notice::Message->new(
961
    my $message = Koha::Notice::Message->new(
956
        {
962
        {
957
            letter_id              => $params->{letter}->{id} || undef,
963
            letter_id              => $params->{letter}->{id} || undef,
(-)a/installer/data/mysql/atomicupdate/bug_35639-add_sms_characters_limitation.pl (+19 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number  => "35639",
5
    description => "Add the SMSSendMaxChar system preference to limit the number of characters in a SMS message",
6
    up          => sub {
7
        my ($args) = @_;
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
10
        # Do you stuffs here
11
        $dbh->do(q{
12
            INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type)
13
            VALUES ('SMSSendMaxChar','','NULL','Add a limit for the number of characters in SMS messages','Integer');
14
        });
15
16
        # sysprefs
17
        say $out "Added new system preference 'SMSSendMaxChar'";
18
    },
19
};
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+1 lines)
Lines 724-729 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
724
('SlipCSS','',NULL,'Slips CSS url.','free'),
724
('SlipCSS','',NULL,'Slips CSS url.','free'),
725
('SMSSendAdditionalOptions', '', '', 'Additional SMS::Send parameters used to send SMS messages', 'free'),
725
('SMSSendAdditionalOptions', '', '', 'Additional SMS::Send parameters used to send SMS messages', 'free'),
726
('SMSSendDriver','','','Sets which SMS::Send driver is used to send SMS messages.','free'),
726
('SMSSendDriver','','','Sets which SMS::Send driver is used to send SMS messages.','free'),
727
('SMSSendMaxChar', '', NULL, 'Add a limit for the number of characters in SMS messages', 'Integer'),
727
('SMSSendPassword', '', '', 'Password used to send SMS messages', 'free'),
728
('SMSSendPassword', '', '', 'Password used to send SMS messages', 'free'),
728
('SMSSendUsername', '', '', 'Username/Login used to send SMS messages', 'free'),
729
('SMSSendUsername', '', '', 'Username/Login used to send SMS messages', 'free'),
729
('SocialNetworks','','facebook|linkedin|email','Enable/Disable social networks links in opac detail pages','Choice'),
730
('SocialNetworks','','facebook|linkedin|email','Enable/Disable social networks links in opac detail pages','Choice'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref (+4 lines)
Lines 239-244 Patrons: Link Here
239
         - driver to send SMS messages.
239
         - driver to send SMS messages.
240
         - "<br>If you would prefer to send SMS via E-mail, set SMSSendDriver to: Email"
240
         - "<br>If you would prefer to send SMS via E-mail, set SMSSendDriver to: Email"
241
         - "<br><strong>NOTE:</strong> Many mobile providers have deprecated support for this feature and it is not recommended for use unless you have a dedicated SMS to Email gateway."
241
         - "<br><strong>NOTE:</strong> Many mobile providers have deprecated support for this feature and it is not recommended for use unless you have a dedicated SMS to Email gateway."
242
         - "<br>Limit messages to"
243
         - pref: SMSSendMaxChar
244
           class: integer
245
         - "characters (no limitation if empty)."
242
     -
246
     -
243
         - "Define a username/login"
247
         - "Define a username/login"
244
         - pref: SMSSendUsername
248
         - pref: SMSSendUsername
(-)a/t/db_dependent/Letters.t (-4 / +20 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use File::Basename qw(dirname);
21
use File::Basename qw(dirname);
22
use Test::More tests => 100;
22
use Test::More tests => 102;
23
use Test::MockModule;
23
use Test::MockModule;
24
use Test::Warn;
24
use Test::Warn;
25
use Test::Exception;
25
use Test::Exception;
Lines 158-163 is( $messages->[0]->{failure_code}, '', 'Failure code for successful message cor Link Here
158
my $yesterday = dt_from_string->subtract( days => 1 );
158
my $yesterday = dt_from_string->subtract( days => 1 );
159
Koha::Notice::Messages->find($messages->[0]->{message_id})->time_queued($yesterday)->store;
159
Koha::Notice::Messages->find($messages->[0]->{message_id})->time_queued($yesterday)->store;
160
160
161
162
# EnqueueLetter - Test characters limitation for SMS
163
$my_message->{letter}->{content} = "a" x 2000;
164
165
t::lib::Mocks::mock_preference('SMSSendMaxChar', '');
166
$message_id = C4::Letters::EnqueueLetter($my_message);
167
my $message = $schema->resultset('MessageQueue')->search({ message_id => $message_id })->next();
168
is( length($message->content()), 2000, "EnqueueLetter doesn't resize the message when SMSSendMaxChar is empty" );
169
$message->delete();
170
171
t::lib::Mocks::mock_preference('SMSSendMaxChar', 100);
172
$message_id = C4::Letters::EnqueueLetter($my_message);
173
$message = $schema->resultset('MessageQueue')->search({ message_id => $message_id })->next();
174
is( length($message->content()), 100, "EnqueueLetter resizes the message according to the value of SMSSendMaxChar" );
175
$message->delete();
176
177
161
# SendQueuedMessages
178
# SendQueuedMessages
162
179
163
throws_ok {
180
throws_ok {
Lines 195-201 is(dt_from_string($messages->[0]->{time_queued}), $yesterday, 'Time queued remai Link Here
195
212
196
# ResendMessage
213
# ResendMessage
197
my $resent = C4::Letters::ResendMessage($messages->[0]->{message_id});
214
my $resent = C4::Letters::ResendMessage($messages->[0]->{message_id});
198
my $message = C4::Letters::GetMessage( $messages->[0]->{message_id});
215
$message = C4::Letters::GetMessage( $messages->[0]->{message_id});
199
is( $resent, 1, 'The message should have been resent' );
216
is( $resent, 1, 'The message should have been resent' );
200
is($message->{status},'pending', 'ResendMessage sets status to pending correctly (bug 12426)');
217
is($message->{status},'pending', 'ResendMessage sets status to pending correctly (bug 12426)');
201
$resent = C4::Letters::ResendMessage($messages->[0]->{message_id});
218
$resent = C4::Letters::ResendMessage($messages->[0]->{message_id});
Lines 1027-1033 subtest 'Test SMS handling in SendQueuedMessages' => sub { Link Here
1027
        qr|Fake send_or_die|,
1044
        qr|Fake send_or_die|,
1028
        "SendAlerts is using the mocked send_or_die routine (claimissues)";
1045
        "SendAlerts is using the mocked send_or_die routine (claimissues)";
1029
1046
1030
    my $message = $schema->resultset('MessageQueue')->search({
1047
    $message = $schema->resultset('MessageQueue')->search({
1031
        borrowernumber => $borrowernumber,
1048
        borrowernumber => $borrowernumber,
1032
        status => 'sent'
1049
        status => 'sent'
1033
    })->next();
1050
    })->next();
1034
- 

Return to bug 35639