Bugzilla – Attachment 164486 Details for
Bug 35639
Long SMS messages are not sent if they exceed the character limitation of the messaging driver
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35639: Trim the messages that are too long before sending them via SMS
Bug-35639-Trim-the-messages-that-are-too-long-befo.patch (text/plain), 6.85 KB, created by
Matthias Le Gac
on 2024-04-05 15:58:39 UTC
(
hide
)
Description:
Bug 35639: Trim the messages that are too long before sending them via SMS
Filename:
MIME Type:
Creator:
Matthias Le Gac
Created:
2024-04-05 15:58:39 UTC
Size:
6.85 KB
patch
obsolete
>From 9a35f993e358697851ee967b804060b67e2e2481 Mon Sep 17 00:00:00 2001 >From: Emily-Rose Francoeur <emily-rose.francoeur@inLibro.com> >Date: Fri, 22 Dec 2023 08:41:39 -0500 >Subject: [PATCH] Bug 35639: Trim the messages that are too long before sending > them via SMS > >I created a new system preference, SMSSendMaxChar, which allows you to set a limit for the number of characters in SMS messages to send. When a limit is set, messages that exceed it will be trimed. > >TEST PLAN >1) Apply the patch >2) Run prove t/db_dependent/Letters.t > >Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> >--- > C4/Letters.pm | 6 +++++ > ...bug_35639-add_sms_characters_limitation.pl | 19 +++++++++++++++ > installer/data/mysql/mandatory/sysprefs.sql | 1 + > .../en/modules/admin/preferences/patrons.pref | 4 ++++ > t/db_dependent/Letters.t | 23 ++++++++++++++++--- > 5 files changed, 50 insertions(+), 3 deletions(-) > create mode 100755 installer/data/mysql/atomicupdate/bug_35639-add_sms_characters_limitation.pl > >diff --git a/C4/Letters.pm b/C4/Letters.pm >index d8dcdba7d2..2dda6ae7f3 100644 >--- a/C4/Letters.pm >+++ b/C4/Letters.pm >@@ -940,6 +940,12 @@ sub EnqueueLetter { > ); > } > >+ if ($params->{message_transport_type} eq 'sms') { >+ my $limit = C4::Context->preference('SMSSendMaxChar'); >+ $params->{letter}->{content} = substr($params->{letter}->{content}, 0, $limit - 3) . '...' >+ if ($limit && length($params->{letter}->{content}) > $limit); >+ } >+ > my $message = Koha::Notice::Message->new( > { > letter_id => $params->{letter}->{id} || undef, >diff --git a/installer/data/mysql/atomicupdate/bug_35639-add_sms_characters_limitation.pl b/installer/data/mysql/atomicupdate/bug_35639-add_sms_characters_limitation.pl >new file mode 100755 >index 0000000000..7c646bad07 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_35639-add_sms_characters_limitation.pl >@@ -0,0 +1,19 @@ >+use Modern::Perl; >+ >+return { >+ bug_number => "35639", >+ description => "Add the SMSSendMaxChar system preference to limit the number of characters in a SMS message", >+ up => sub { >+ my ($args) = @_; >+ my ( $dbh, $out ) = @$args{qw(dbh out)}; >+ >+ # Do you stuffs here >+ $dbh->do(q{ >+ INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) >+ VALUES ('SMSSendMaxChar','','NULL','Add a limit for the number of characters in SMS messages','Integer'); >+ }); >+ >+ # sysprefs >+ say $out "Added new system preference 'SMSSendMaxChar'"; >+ }, >+}; >diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql >index 0d040f2fd9..69a863e2a4 100644 >--- a/installer/data/mysql/mandatory/sysprefs.sql >+++ b/installer/data/mysql/mandatory/sysprefs.sql >@@ -713,6 +713,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` > ('SkipHoldTrapOnNotForLoanValue','',NULL,'If set, Koha will never trap items for hold with this notforloan value','Integer'), > ('SlipCSS','',NULL,'Slips CSS url.','free'), > ('SMSSendDriver','','','Sets which SMS::Send driver is used to send SMS messages.','free'), >+('SMSSendMaxChar', '', NULL, 'Add a limit for the number of characters in SMS messages', 'Integer'), > ('SMSSendPassword', '', '', 'Password used to send SMS messages', 'free'), > ('SMSSendUsername', '', '', 'Username/Login used to send SMS messages', 'free'), > ('SocialNetworks','','facebook|linkedin|email','Enable/Disable social networks links in opac detail pages','Choice'), >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref >index f48ba4c13c..d25c5b3615 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref >@@ -229,6 +229,10 @@ Patrons: > - driver to send SMS messages. > - "<br>If you would prefer to send SMS via E-mail, set SMSSendDriver to: Email" > - "<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." >+ - "<br>Limit messages to" >+ - pref: SMSSendMaxChar >+ class: integer >+ - "characters (no limitation if empty)." > - > - "Define a username/login" > - pref: SMSSendUsername >diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t >index eff6e3fd40..423b2e2e0f 100755 >--- a/t/db_dependent/Letters.t >+++ b/t/db_dependent/Letters.t >@@ -18,7 +18,7 @@ > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >-use Test::More tests => 100; >+use Test::More tests => 97; > use Test::MockModule; > use Test::Warn; > use Test::Exception; >@@ -157,6 +157,23 @@ is( $messages->[0]->{failure_code}, '', 'Failure code for successful message cor > my $yesterday = dt_from_string->subtract( days => 1 ); > Koha::Notice::Messages->find($messages->[0]->{message_id})->time_queued($yesterday)->store; > >+ >+# EnqueueLetter - Test characters limitation for SMS >+$my_message->{letter}->{content} = "a" x 2000; >+ >+t::lib::Mocks::mock_preference('SMSSendMaxChar', ''); >+$message_id = C4::Letters::EnqueueLetter($my_message); >+my $message = $schema->resultset('MessageQueue')->search({ message_id => $message_id })->next(); >+is( length($message->content()), 2000, "EnqueueLetter doesn't resize the message when SMSSendMaxChar is empty" ); >+$message->delete(); >+ >+t::lib::Mocks::mock_preference('SMSSendMaxChar', 100); >+$message_id = C4::Letters::EnqueueLetter($my_message); >+$message = $schema->resultset('MessageQueue')->search({ message_id => $message_id })->next(); >+is( length($message->content()), 100, "EnqueueLetter resizes the message according to the value of SMSSendMaxChar" ); >+$message->delete(); >+ >+ > # SendQueuedMessages > > throws_ok { >@@ -194,7 +211,7 @@ is(dt_from_string($messages->[0]->{time_queued}), $yesterday, 'Time queued remai > > # ResendMessage > my $resent = C4::Letters::ResendMessage($messages->[0]->{message_id}); >-my $message = C4::Letters::GetMessage( $messages->[0]->{message_id}); >+$message = C4::Letters::GetMessage( $messages->[0]->{message_id}); > is( $resent, 1, 'The message should have been resent' ); > is($message->{status},'pending', 'ResendMessage sets status to pending correctly (bug 12426)'); > $resent = C4::Letters::ResendMessage($messages->[0]->{message_id}); >@@ -958,7 +975,7 @@ subtest 'Test SMS handling in SendQueuedMessages' => sub { > qr|Fake send_or_die|, > "SendAlerts is using the mocked send_or_die routine (claimissues)"; > >- my $message = $schema->resultset('MessageQueue')->search({ >+ $message = $schema->resultset('MessageQueue')->search({ > borrowernumber => $borrowernumber, > status => 'sent' > })->next(); >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35639
:
160243
|
160684
|
164486
|
166887