From 6c3c1ab2d0e7b0ae1e24489c0006ae82089a4c06 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Wed, 7 Feb 2024 17:11:58 +0100 Subject: [PATCH] Bug 36022: Add default recipient SMS number country code Add SMSSendDefaultCountryCode syspref to prepend country code to non international SMS numbers. To test: TODO --- C4/SMS.pm | 15 ++++++++++++++- ...36022-add-SMSSendDefaultCountryCode-syspref.pl | 14 ++++++++++++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../en/modules/admin/preferences/patrons.pref | 5 +++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100755 installer/data/mysql/atomicupdate/bug-36022-add-SMSSendDefaultCountryCode-syspref.pl diff --git a/C4/SMS.pm b/C4/SMS.pm index ce3358f66ab..6a9ac750d9a 100644 --- a/C4/SMS.pm +++ b/C4/SMS.pm @@ -116,9 +116,22 @@ sub send_sms { %args, ); + my $default_country_code = C4::Context->preference("SMSSendDefaultCountryCode"); + my $destination = $params->{destination}; + + # Default country code set and is local phone number + if ($default_country_code && $destination =~ /^[^+]/) { + # Ensure country code has leading '+' + $default_country_code =~ s/^[^+]/+$&/; + # Strip leading zeroes + $destination =~ s/^0+//; + # Prepend default country code + $destination = $default_country_code . $destination; + } + # Send a message $sent = $sender->send_sms( - to => $params->{destination}, + to => $destination, text => $params->{message}, ); }; diff --git a/installer/data/mysql/atomicupdate/bug-36022-add-SMSSendDefaultCountryCode-syspref.pl b/installer/data/mysql/atomicupdate/bug-36022-add-SMSSendDefaultCountryCode-syspref.pl new file mode 100755 index 00000000000..e34ac28996d --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug-36022-add-SMSSendDefaultCountryCode-syspref.pl @@ -0,0 +1,14 @@ +use Modern::Perl; + +return { + bug_number => "36022", + description => "Add SMSSendDefaultCountryCode system preference", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + $dbh->do(q{ INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type) VALUES ('SMSSendDefaultCountryCode ', NULL, NULL, 'Default SMS::Send driver recipient phone number country code', 'Integer') }); + # sysprefs + say $out "Added new system preference 'SMSSendDefaultCountryCode'"; + }, +}; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index fad32d896e5..684f02a71ed 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -680,6 +680,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('SIP2SortBinMapping','',NULL,'Use the following mappings to determine the sort_bin of a returned item. The mapping should be on the form \"branchcode:item field:item field value:sort bin number\", with one mapping per line.','free'), ('SkipHoldTrapOnNotForLoanValue','',NULL,'If set, Koha will never trap items for hold with this notforloan value','Integer'), ('SlipCSS','',NULL,'Slips CSS url.','free'), +('SMSSendDefaultCountryCode ',NULL,NULL,'Default SMS::Send driver recipient phone number country code','Integer'), ('SMSSendDriver','','','Sets which SMS::Send driver is used to send SMS messages.','free'), ('SMSSendPassword', '', '', 'Password used to send SMS messages', 'free'), ('SMSSendUsername', '', '', 'Username/Login used to send SMS messages', 'free'), 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 0adb1ae1d7b..5140f7ceaeb 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 @@ -217,6 +217,11 @@ Patrons: - driver to send SMS messages. - "
If you would prefer to send SMS via E-mail, set SMSSendDriver to: Email" - "
NOTE: 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." + - + - "Prepend the country code" + - pref: SMSSendDefaultCountryCode + - class: integer + - "for SMS::Driver recipient phone numbers. The country code shound not include a leading \"+\"." - - "Define a username/login" - pref: SMSSendUsername -- 2.43.0