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

(-)a/C4/Letters.pm (+6 lines)
Lines 940-945 sub EnqueueLetter { Link Here
940
        );
940
        );
941
    }
941
    }
942
942
943
    if ($params->{message_transport_type} eq 'sms') {
944
        my $limit = C4::Context->preference('SMSSendMaxChar');
945
        $params->{letter}->{content} = substr($params->{letter}->{content}, 0, $limit - 3) . '...'
946
            if ($limit && length($params->{letter}->{content}) > $limit);
947
    }
948
943
    my $message = Koha::Notice::Message->new(
949
    my $message = Koha::Notice::Message->new(
944
        {
950
        {
945
            letter_id              => $params->{letter}->{id} || undef,
951
            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 713-718 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
713
('SkipHoldTrapOnNotForLoanValue','',NULL,'If set, Koha will never trap items for hold with this notforloan value','Integer'),
713
('SkipHoldTrapOnNotForLoanValue','',NULL,'If set, Koha will never trap items for hold with this notforloan value','Integer'),
714
('SlipCSS','',NULL,'Slips CSS url.','free'),
714
('SlipCSS','',NULL,'Slips CSS url.','free'),
715
('SMSSendDriver','','','Sets which SMS::Send driver is used to send SMS messages.','free'),
715
('SMSSendDriver','','','Sets which SMS::Send driver is used to send SMS messages.','free'),
716
('SMSSendMaxChar', '', NULL, 'Add a limit for the number of characters in SMS messages', 'Integer'),
716
('SMSSendPassword', '', '', 'Password used to send SMS messages', 'free'),
717
('SMSSendPassword', '', '', 'Password used to send SMS messages', 'free'),
717
('SMSSendUsername', '', '', 'Username/Login used to send SMS messages', 'free'),
718
('SMSSendUsername', '', '', 'Username/Login used to send SMS messages', 'free'),
718
('SocialNetworks','','facebook|linkedin|email','Enable/Disable social networks links in opac detail pages','Choice'),
719
('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 229-234 Patrons: Link Here
229
         - driver to send SMS messages.
229
         - driver to send SMS messages.
230
         - "<br>If you would prefer to send SMS via E-mail, set SMSSendDriver to: Email"
230
         - "<br>If you would prefer to send SMS via E-mail, set SMSSendDriver to: Email"
231
         - "<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."
231
         - "<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."
232
         - "<br>Limit messages to"
233
         - pref: SMSSendMaxChar
234
           class: integer
235
         - "characters (no limitation if empty)."
232
     -
236
     -
233
         - "Define a username/login"
237
         - "Define a username/login"
234
         - pref: SMSSendUsername
238
         - pref: SMSSendUsername
(-)a/t/db_dependent/Letters.t (-4 / +20 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 100;
21
use Test::More tests => 97;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
use Test::Exception;
24
use Test::Exception;
Lines 157-162 is( $messages->[0]->{failure_code}, '', 'Failure code for successful message cor Link Here
157
my $yesterday = dt_from_string->subtract( days => 1 );
157
my $yesterday = dt_from_string->subtract( days => 1 );
158
Koha::Notice::Messages->find($messages->[0]->{message_id})->time_queued($yesterday)->store;
158
Koha::Notice::Messages->find($messages->[0]->{message_id})->time_queued($yesterday)->store;
159
159
160
161
# EnqueueLetter - Test characters limitation for SMS
162
$my_message->{letter}->{content} = "a" x 2000;
163
164
t::lib::Mocks::mock_preference('SMSSendMaxChar', '');
165
$message_id = C4::Letters::EnqueueLetter($my_message);
166
my $message = $schema->resultset('MessageQueue')->search({ message_id => $message_id })->next();
167
is( length($message->content()), 2000, "EnqueueLetter doesn't resize the message when SMSSendMaxChar is empty" );
168
$message->delete();
169
170
t::lib::Mocks::mock_preference('SMSSendMaxChar', 100);
171
$message_id = C4::Letters::EnqueueLetter($my_message);
172
$message = $schema->resultset('MessageQueue')->search({ message_id => $message_id })->next();
173
is( length($message->content()), 100, "EnqueueLetter resizes the message according to the value of SMSSendMaxChar" );
174
$message->delete();
175
176
160
# SendQueuedMessages
177
# SendQueuedMessages
161
178
162
throws_ok {
179
throws_ok {
Lines 194-200 is(dt_from_string($messages->[0]->{time_queued}), $yesterday, 'Time queued remai Link Here
194
211
195
# ResendMessage
212
# ResendMessage
196
my $resent = C4::Letters::ResendMessage($messages->[0]->{message_id});
213
my $resent = C4::Letters::ResendMessage($messages->[0]->{message_id});
197
my $message = C4::Letters::GetMessage( $messages->[0]->{message_id});
214
$message = C4::Letters::GetMessage( $messages->[0]->{message_id});
198
is( $resent, 1, 'The message should have been resent' );
215
is( $resent, 1, 'The message should have been resent' );
199
is($message->{status},'pending', 'ResendMessage sets status to pending correctly (bug 12426)');
216
is($message->{status},'pending', 'ResendMessage sets status to pending correctly (bug 12426)');
200
$resent = C4::Letters::ResendMessage($messages->[0]->{message_id});
217
$resent = C4::Letters::ResendMessage($messages->[0]->{message_id});
Lines 958-964 subtest 'Test SMS handling in SendQueuedMessages' => sub { Link Here
958
        qr|Fake send_or_die|,
975
        qr|Fake send_or_die|,
959
        "SendAlerts is using the mocked send_or_die routine (claimissues)";
976
        "SendAlerts is using the mocked send_or_die routine (claimissues)";
960
977
961
    my $message = $schema->resultset('MessageQueue')->search({
978
    $message = $schema->resultset('MessageQueue')->search({
962
        borrowernumber => $borrowernumber,
979
        borrowernumber => $borrowernumber,
963
        status => 'sent'
980
        status => 'sent'
964
    })->next();
981
    })->next();
965
- 

Return to bug 35639