From 63d1926abdca3522fcdede720f0ab77bc1196768 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 14 Sep 2021 13:31:09 -0400 Subject: [PATCH] Bug 21781 - message_transport_type should allow fallbacks --- C4/Acquisition.pm | 2 +- Koha/Patron.pm | 22 +++++++++++++++++++ circ/pendingreserves.pl | 2 +- .../en/modules/admin/preferences/patrons.pref | 6 +++++ misc/cronjobs/membership_expiry.pl | 4 ++-- opac/opac-shareshelf.pl | 2 +- 6 files changed, 33 insertions(+), 5 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 3d74f847a6..a0b24c7c69 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -3017,7 +3017,7 @@ sub NotifyOrderUsers { letter => $letter, borrowernumber => $borrowernumber, LibraryName => C4::Context->preference("LibraryName"), - message_transport_type => 'email', + message_transport_type => $patron->message_transport_type_for('email'), } ) or warn "can't enqueue letter $letter"; } diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 941dace0df..5be69ad831 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1273,6 +1273,28 @@ sub first_valid_email_address { return $self->email() || $self->emailpro() || $self->B_email() || q{}; } +=head3 message_transport_type_for + +Given a message transport type, will return the transport type that should be used, +including a fallback if needed. + +my $mtt = $patron->message_transport_type_for('email'); + +=cut + +sub message_transport_type_for { + my ( $self, $mtt ) = @_; + + if ( $mtt eq 'email' ) { + return 'sms' + if C4::Context->preference("FallbackToSMSIfNoEmail") + && $self->smsalertnumber + && !$self->notice_email_address; + } + + return $mtt; +} + =head3 get_club_enrollments =cut diff --git a/circ/pendingreserves.pl b/circ/pendingreserves.pl index 0b2fea2195..beaaa15480 100755 --- a/circ/pendingreserves.pl +++ b/circ/pendingreserves.pl @@ -89,7 +89,7 @@ if ( $op eq 'cancel_reserve' and $reserve_id ) { C4::Letters::EnqueueLetter( { letter => $letter, borrowernumber => $patron->borrowernumber, - message_transport_type => 'email', + message_transport_type => $patron->message_transport_type_for('email'), from_address => $from_address, } ); 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 5a6f1bd5a4..9063239f63 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 @@ -148,6 +148,12 @@ Patrons: 1: Send 0: "Don't send" - an email to newly created patrons with their account details. + - + - pref: FallbackToSMSIfNoEmail + choices: + 1: Enable + 0: Disable + - sending notices by SMS if patron has no email address. - - pref: UseEmailReceipts choices: diff --git a/misc/cronjobs/membership_expiry.pl b/misc/cronjobs/membership_expiry.pl index 41003674e2..b4e8cb54dc 100755 --- a/misc/cronjobs/membership_expiry.pl +++ b/misc/cronjobs/membership_expiry.pl @@ -225,9 +225,9 @@ while ( my $recent = $upcoming_mem_expires->next ) { } else { C4::Letters::EnqueueLetter({ letter => $letter, - borrowernumber => $recent->borrowernumber, + borrowernumber => $recent->borrowernumber, from_address => $from_address, - message_transport_type => 'email', + message_transport_type => $recent->message_transport_type_for('email'), }); } } diff --git a/opac/opac-shareshelf.pl b/opac/opac-shareshelf.pl index 701871bafc..16d8caef2a 100755 --- a/opac/opac-shareshelf.pl +++ b/opac/opac-shareshelf.pl @@ -182,7 +182,7 @@ sub notify_owner { letter => $letter, message_transport_type => 'email', from_address => C4::Context->preference('KohaAdminEmailAddress'), - to_address => $toaddr, + message_transport_type => $patron->message_transport_type_for('email'), } ); } -- 2.30.1 (Apple Git-130)