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 <david@davidnind.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
ThibaudGLT 2021-12-10 15:02:03 +00:00 committed by Kyle Hall
parent 3c8a197484
commit d8e3563d32
4 changed files with 39 additions and 17 deletions

View File

@ -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');
}

View File

@ -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'),

View File

@ -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: "

View File

@ -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 $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.',
};
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;
C4::Letters::EnqueueLetter(
{ letter => $letter,
borrowernumber => undef,
message_transport_type => 'email',
attachments => [$attachment],
to_address => $branch_email_address,
}
) unless $test_mode;
}
}
}