From d8e3563d32060039d2a67cf766fc6c5bac5747b3 Mon Sep 17 00:00:00 2001 From: ThibaudGLT Date: Fri, 10 Dec 2021 15:02:03 +0000 Subject: [PATCH] Bug 20076: Add syspref to remove overdues notification by email to staff if user has no email address I took the same test plan as victor but I added the system preference to manage the case more easily, especially for users who do not have access to the koha server. Test plan 1. Check the size of the message queue With the following SQL query (using an SQL report if you want) SELECT COUNT(*) FROM message_queue; 2. Run misc/cronjobs/overdue_notices.pl 3. Check the size of the message queue To ensure that no other overdues will create noise in this test plan. Or you can take them into account. 4. Choose a patron with no email address 5. Create an overdue (checkout an item and unfold "Checkout settings" and set a date in the past which is compatible with what you find in staff:/cgi-bin/koha/tools/overduerules.pl 6. Run misc/cronjobs/overdue_notices.pl 7. Check that you have two new messages in the queue 8. Inspect these two messages SELECT * FROM message_queue ORDER BY time_queued DESC LIMIT 2 \G 1. One has the type "print" and the borrowernumber matching the patron. 2. The other has subject: Overdue Notices borrowernumber: NULL message_transport_type: email and contains "These messages were not sent directly to the patrons." This is the one we don't want anymore. Because it's now obsolete due to the first message. 9. Apply this patch 10. Run updatedabatase.pl 11. Change syspref 'EmailOverduesNoEmail' to "Don't send" 12. Delete data from message_queue (if you have access) for a cleaner view 13. Run again misc/cronjobs/overdue_notices.pl 14. Check that only the print message is now generated and not the "Overdue Notices" one. https://bugs.koha-community.org/show_bug.cgi?id=20076 Signed-off-by: David Nind Signed-off-by: Fridolin Somers Signed-off-by: Kyle M Hall --- ...ystem-preference-EmailOverduesNoEmail.perl | 9 ++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../en/modules/admin/preferences/admin.pref | 8 ++++ misc/cronjobs/overdue_notices.pl | 42 ++++++++++--------- 4 files changed, 41 insertions(+), 19 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/add-system-preference-EmailOverduesNoEmail.perl diff --git a/installer/data/mysql/atomicupdate/add-system-preference-EmailOverduesNoEmail.perl b/installer/data/mysql/atomicupdate/add-system-preference-EmailOverduesNoEmail.perl new file mode 100644 index 0000000000..783e22d80d --- /dev/null +++ b/installer/data/mysql/atomicupdate/add-system-preference-EmailOverduesNoEmail.perl @@ -0,0 +1,9 @@ +$DBversion = 'XXX'; +if ( CheckVersion($DBversion ) ) { + $dbh->do(q{ + INSERT IGNORE INTO systempreferences (`variable`,`value`,`options`,`explanation`,`type`) + VALUES ('EmailOverduesNoEmail','0','','Set mail sending to staff for patron has overdues but no email address', 'YesNo') + }); + + NewVersion( $DBversion,'20076','Add system preference EmailOverduesNoEmail'); +} diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 68877bbbce..c048130ab2 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -193,6 +193,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('ElasticsearchCrossFields', '1', '', 'Enable "cross_fields" option for searches using Elastic search.', 'YesNo'), ('EmailAddressForSuggestions','','',' If you choose EmailAddressForSuggestions you have to enter a valid email address: ','free'), ('emailLibrarianWhenHoldIsPlaced','0',NULL,'If ON, emails the librarian whenever a hold is placed','YesNo'), +('EmailOverduesNoEmail','0',NULL,'Set mail sending to staff for patron has overdues but no email address','YesNo'), ('EmailPurchaseSuggestions','0','0|EmailAddressForSuggestions|BranchEmailAddress|KohaAdminEmailAddress','Choose email address that new purchase suggestions will be sent to: ','Choice'), ('EnableAdvancedCatalogingEditor','0','','Enable the Rancor advanced cataloging editor','YesNo'), ('EnableBorrowerFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to a borrower record.','YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref index 3263d6d031..8ceb44640b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref @@ -76,6 +76,14 @@ Administration: choices: 1: "The logged-in library" 0: "All libraries" + + - + - pref: EmailOverduesNoEmail + choices: + 1: "Don't send" + 0: "Send" + - "mail to staff for patron has overdues but no email address" + Login options: - - "Inactivity timeout in seconds to automatically log out users: " diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index a1c2211628..b704d55468 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -376,6 +376,7 @@ if (@branchcodes) { my $branch_word = scalar @branches > 1 ? 'branches' : 'branch'; $verbose and warn "$branch_word @branches have overdue rules\n"; + } else { $verbose and warn "No active overduerules for $branchcodes_word '@branchcodes'\n"; @@ -849,25 +850,28 @@ END_SQL } $content .= join( "\n", @output_chunks ); - my $attachment = { - filename => defined $csvfilename ? 'attachment.csv' : 'attachment.txt', - type => 'text/plain', - content => $content, - }; - - my $letter = { - title => 'Overdue Notices', - content => 'These messages were not sent directly to the patrons.', - }; - - C4::Letters::EnqueueLetter( - { letter => $letter, - borrowernumber => undef, - message_transport_type => 'email', - attachments => [$attachment], - to_address => $branch_email_address, - } - ) unless $test_mode; + my $EmailOverduesNoEmail = C4::Context->preference('EmailOverduesNoEmail'); + if ( $EmailOverduesNoEmail == 0) { + my $attachment = { + filename => defined $csvfilename ? 'attachment.csv' : 'attachment.txt', + type => 'text/plain', + content => $content, + }; + + my $letter = { + title => 'Overdue Notices', + content => 'These messages were not sent directly to the patrons.', + }; + + C4::Letters::EnqueueLetter( + { letter => $letter, + borrowernumber => undef, + message_transport_type => 'email', + attachments => [$attachment], + to_address => $branch_email_address, + } + ) unless $test_mode; + } } } -- 2.39.5