From a0acc0174adf6fe0c224e9cb3446030effbebf63 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Wed, 22 Apr 2020 02:46:02 +0000 Subject: [PATCH] Bug 21781: Fallback to SMS if no email address where email address hardcoded Extend use of FallbackToSMSIfNoEmail syspref to fallback to SMS if no patron email address outside of it's current usage sending suggestion notices. Test plan for C4/Acquisition.pm: 1. Input a value into SMSSendDriver syspref 2. Create a patron with sms (under Member messaging preferences) and no email address 3. In Acquistions module make currency, active budget, fund, vendor 4. Create a basket 5. Add to basket. Click to add 'From a new (empty) record' 6. Under 'Patrons' header add a user and search for your patron (added in #1) 7. Submit new order 8. Receive the order: 'Close this basket' 'Receive shipment' Submit invoice page Select 'Receive' link on right hand side of page Tick checkbox to add 1 quantity of item and Save 9. Revisit your patrons page and in the 'Notices' tab you'll see a 'Order received' notice with type of 'email' 11. Apply patch and restart plack 12. Repeat steps 4-9 and observe the 'Order received' notice has a type of SMS Test plan for amendment to circ/pendingreserves.pl (patch has been applied in 'Test plan for C4/Acquisition.pm): 1. Set 'FallbackToSMSIfNoEmail' syspref to 'Disable' 2. Set CanMarkHoldsToPullAsLost syspref to 'Allow to mark items as lost and notify the patron' 3. Using the patron from test plan for C4/Acquisitions.pm (i.e. sms alert number and no email) place a hold on an item currently available 4. Visit Circulation > Holds to pull 5. Select 'Mark lost and notify patron' 6. Return to patron page look in 'Notices' tab and observe 'Hold has been cancelled' notice has type of 'email' 7. Change 'FallbackToSMSIfNoEmail' to 'Enable' and repeat steps 3,4,5,6 and observe the new 'Hold has been cancelled' notice has type 'sms' Test plan for amendment to misc/cronjobs/automatic_renewals.pl (patch has been applied already): 1. Set 'FallbackToSMSIfNoEmail' syspref to 'Disable' 2. Enable automatic renewals in Administration > Circulation and fine rules 3. Checkout an item to our patron and set due date in the past 4. cd into misc/cronjobs 5. Jump into koha-shell and run automatic_renewals.pl cronjob sudo koha-shell ./automatic_renewals.pl --confirm --send-notices 6. Observe in patron records 'Notices' tab there is a 'Auto renewals' notice with type 'email' 7. Set 'FallbackToSMSIfNoEmail' syspref to 'Enable' and repeat steps 3,4,5,6 and observe the new 'Auto renewals' notice is type 'sms' Test plan for amendment to misc/cronjobs/membership_expiry.pl (patch has been applied already): 1. Set 'FallbackToSMSIfNoEmail' syspref to 'Disable' 2. Set 'MembershipExpiryDaysNotice' to '1' 3. Edit our patrons record setting 'Expiry date' to 1 day in future 4. cd to misc/cronjobs directory 5. Jump into koha-shell and run membership_expiry.pl cronjob: sudo koha-shell ./membership_expiry.pl -c 6. Visit the patron record's 'Notices' tab and observe 'Account expiration' notice with type 'email' 7. Change 'FallbackToSMSIfNoEmail' syspref to 'Enable' 8. Reset patrons epxiration date to 1 day in future 9. Repeat step 4,5,6 and observe new 'Account expiration' notice is type 'sms' Test plan for opac/opac-shareshelf.pl (patch has been applied already): 1. Set 'FallbackToSMSIfNoEmail' syspref to 'Disable' 2. Set 'OpacAllowSharingPrivateLists' syspref to 'Allow' 3. Ensure OPACBaseURL is set 4. In OPAC log in as the patron with set smsalertnumber and no email 5. Create a private list, select 'Share' link, input email address and submit 6. Back in staff client make a new patron record 7. Return to OPAC and login as patron from step #5 8. Query database: select content from message_queue where letter_code='SHARE_INVITE'; 9. Click on the link in the message_queue notice 10. OPAC loads 11. Query database again: select to_address, message_transport_type from message_queue where letter_code='SHARE_ACCEPT'; 12. Observe there is no 'Share on list accepted' notice 13. Set 'FallbackToSMSIfNoEmail' to 'Enable' and repeat steps 4,5,7,8, 9,10,11,12 and observe there is a 'Share on list accepted' notice with to_address = smsalertnumber and message_transport_type is 'sms' 14. Set 'FallbackToSMSIfNoEmail' to 'disable' and edit the patron with smsalertnumber set and no email setting an email address and repeat steps 4,5,7,8,9,10,11,12 and observe there is a 'Share on list accepted' notice with the to_address of the email you set and message_transport_type of 'email' Sponsored-by: Catalyst IT --- C4/Acquisition.pm | 5 ++++- circ/pendingreserves.pl | 4 +++- .../intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref | 2 +- misc/cronjobs/automatic_renewals.pl | 4 +++- misc/cronjobs/membership_expiry.pl | 5 ++++- opac/opac-shareshelf.pl | 9 +++++++-- 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index da0a9b4d78..6bc2e67147 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -3180,12 +3180,15 @@ sub NotifyOrderUsers { }, ); if ( $letter ) { + + my $transport = (C4::Context->preference("FallbackToSMSIfNoEmail")) && ($patron->smsalertnumber) && (!$patron->email) ? 'sms' : 'email'; + C4::Letters::EnqueueLetter( { letter => $letter, borrowernumber => $borrowernumber, LibraryName => C4::Context->preference("LibraryName"), - message_transport_type => 'email', + message_transport_type => $transport, } ) or warn "can't enqueue letter $letter"; } diff --git a/circ/pendingreserves.pl b/circ/pendingreserves.pl index 7f2062942a..e1e71e3e71 100755 --- a/circ/pendingreserves.pl +++ b/circ/pendingreserves.pl @@ -85,10 +85,12 @@ if ( $op eq 'cancel_reserve' and $reserve_id ) { if ( $letter ) { my $admin_email_address = $library->branchemail || C4::Context->preference('KohaAdminEmailAddress'); + my $transport = (C4::Context->preference("FallbackToSMSIfNoEmail")) && ($patron->smsalertnumber) && (!$patron->email) ? 'sms' : 'email'; + C4::Letters::EnqueueLetter( { letter => $letter, borrowernumber => $patron->borrowernumber, - message_transport_type => 'email', + message_transport_type => $transport, from_address => $admin_email_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 6990dfa62d..bdf2e106f7 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 @@ -29,7 +29,7 @@ Patrons: choices: yes: Enable no: Disable - - Send purchase suggestion messages by SMS if no patron email is defined. + - Send notices by SMS if no patron email is defined. - - pref: UseEmailReceipts choices: diff --git a/misc/cronjobs/automatic_renewals.pl b/misc/cronjobs/automatic_renewals.pl index a76f7dfb35..3704a58f69 100755 --- a/misc/cronjobs/automatic_renewals.pl +++ b/misc/cronjobs/automatic_renewals.pl @@ -140,10 +140,12 @@ if ( $send_notices ) { my $library = Koha::Libraries->find( $patron->branchcode ); my $admin_email_address = $library->branchemail || C4::Context->preference('KohaAdminEmailAddress'); + my $transport = (C4::Context->preference("FallbackToSMSIfNoEmail")) && ($patron->smsalertnumber) && (!$patron->email) ? 'sms' : 'email'; + C4::Letters::EnqueueLetter( { letter => $letter, borrowernumber => $borrowernumber, - message_transport_type => 'email', + message_transport_type => $transport, from_address => $admin_email_address, } ) if $confirm; diff --git a/misc/cronjobs/membership_expiry.pl b/misc/cronjobs/membership_expiry.pl index 5038ce1f9f..b804fd1624 100755 --- a/misc/cronjobs/membership_expiry.pl +++ b/misc/cronjobs/membership_expiry.pl @@ -198,11 +198,14 @@ while ( my $recent = $upcoming_mem_expires->next ) { if( $nomail ) { print $letter->{'content'}."\n"; } else { + + my $transport = (C4::Context->preference("FallbackToSMSIfNoEmail")) && ($recent->smsalertnumber) && (!$recent->email) ? 'sms' : 'email'; + C4::Letters::EnqueueLetter({ letter => $letter, borrowernumber => $recent->borrowernumber, from_address => $from_address, - message_transport_type => 'email', + message_transport_type => $transport, }); } } diff --git a/opac/opac-shareshelf.pl b/opac/opac-shareshelf.pl index 34a17788ed..32bff2cf20 100755 --- a/opac/opac-shareshelf.pl +++ b/opac/opac-shareshelf.pl @@ -165,8 +165,12 @@ sub notify_owner { my $patron = Koha::Patrons->find( $param->{owner} ); return unless $patron; - my $toaddr = $patron->notice_email_address or return; + my $transport = (C4::Context->preference("FallbackToSMSIfNoEmail")) && ($patron->smsalertnumber) && (!$patron->email) ? 'sms' : 'email'; + warn $transport; + my $toaddr = $transport eq 'sms' ? $patron->smsalertnumber : $patron->notice_email_address or return; + + warn $toaddr; #prepare letter my $letter = C4::Letters::GetPreparedLetter( module => 'members', @@ -181,7 +185,7 @@ sub notify_owner { C4::Letters::EnqueueLetter( { letter => $letter, - message_transport_type => 'email', + message_transport_type => $transport, from_address => C4::Context->preference('KohaAdminEmailAddress'), to_address => $toaddr, } @@ -209,6 +213,7 @@ sub process_addrlist { sub send_invitekey { my ($param) = @_; + my $fromaddr = C4::Context->preference('KohaAdminEmailAddress'); my $url = C4::Context->preference('OPACBaseURL') -- 2.11.0