From e180a6a98da267ffbdb93b3bf7101980b9b93d0d Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 14 May 2020 13:21:22 +0000 Subject: [PATCH] Bug 18532: add individual issues to digest notice and hide auto_renewals messaging preference when not needed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch enhances auto_renewals message, removes auto_renewals messaging preference when AutoRenewalNotices is not set to ‘preferences’ and uses that preference to send notices in automatic_renewals.pl script. To test: 1. Apply patches 2. updatedatabase 3. make sure automatic renewals are allowed in circ rules, have a positive number of allowed renewals and a positive number for renewal period 4. Check AutoRenewalNotices preference SUCCESS => AutoRenewalNotices has the value ‘cron’ (means that It keeps the usual behaviour) 5. Checkout two items for a patron, and set them as automatic renewal and set due date as your current yesterday 6. perl misc/cronjobs/automatic_renewals.pl -c -v SUCCESS => items were renewed, but there is no message in message_queue table in mysql 7. Repeat step 5 8. perl misc/cronjobs/automatic_renewals.pl -c -s -v SUCCESS => items were renewed, and there is one message per item in message_queue table in mysql 9. Change AutoRenewalNotices to ‘never’ 10. Repeat step 5 11. perl misc/cronjobs/automatic_renewals.pl -c -s -v SUCCESS => items were renewed, but there is no message in message_queue table in mysql, even with the -s switch 12. Check any patron’s category, and any detail page in staff or OPAC interface, and in any of them you should find Auto Renewals messaging preference 13. Change AutoRenewalNotices to ‘preferences’ 14. Repeat step 12, but this time all of them shows the Auto Renewals messaging preference. 15. Repeat step 5 with a patron that has no messaging preference setted 16. perl misc/cronjobs/automatic_renewals.pl -c -s -v SUCCESS => items were renewed, but there is no message in message_queue table in mysql, because patron didn’t choose to receive messages 17. Grab a category and modify auto renewals messaging preferences, and save 18. Create a new patron from that category. SUCCESS => created patron has the same messaging preference for auto renewals 19. Grab that patron and change auto renewals messaging preference to email but not digest 20. Repeat step 5 for that last patron. 21. perl misc/cronjobs/automatic_renewals.pl -c -v SUCCESS => Items were renewed, and there is a message for each item in message_queue table in mysql. 22. Change auto renewals messaging preference from the same patron and set to email and digest. 23. Repeat step 5. 24. perl misc/cronjobs/automatic_renewals.pl -c -v SUCCESS => items where renewed, and now there is only one message in message_queue table with the details of both renewed items. 25. Check that any changes to a patron’s auto renewals messaging preference in staff is reflected in OPAC, and the other way arround too. 26. Sign off --- .../data/mysql/atomicupdate/bug-18532.perl | 16 +++++++--- .../mysql/pl-PL/mandatory/sample_notices.sql | 31 +++++++++---------- .../en/includes/messaging-preference-form.inc | 1 + .../bootstrap/en/modules/opac-messaging.tt | 1 + misc/cronjobs/automatic_renewals.pl | 13 +++++--- 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/installer/data/mysql/atomicupdate/bug-18532.perl b/installer/data/mysql/atomicupdate/bug-18532.perl index 4bb601dd6e..1c75ca19fc 100644 --- a/installer/data/mysql/atomicupdate/bug-18532.perl +++ b/installer/data/mysql/atomicupdate/bug-18532.perl @@ -4,11 +4,19 @@ if( CheckVersion( $DBversion ) ) { $dbh->do( qq{ INSERT IGNORE INTO letter (module, code, name, title, content, message_transport_type) VALUES ('circulation', 'AUTO_RENEWALS_DGST', 'notification on auto renewing', 'Auto renewals (Digest)', "Dear [% borrower.firstname %] [% borrower.surname %], - [% IF checkout.auto_renew_errors %] - There were [% checkout.auto_renew_errors %] items that where not correctly renewed. + [% IF error %] + There were [% error %] items that were not correctly renewed. [% END %] - [% IF checkout.auto_renew %] - There were [% checkout.auto_renew %] items that where correctly renewed. + [% IF success %] + There were [% success %] items that where correctly renewed. + [% END %] + [% FOREACH checkout IN checkouts %] + [% checkout.item.biblio.title %] : [% checkout.item.barcode %] + [% IF !checkout.auto_renew_error %] + was renewed until [% checkout.date_due %] + [% ELSE %] + was not renewed with error: [% checkout.auto_renew_error %] + [% END %] [% END %] ", 'email'); }); diff --git a/installer/data/mysql/pl-PL/mandatory/sample_notices.sql b/installer/data/mysql/pl-PL/mandatory/sample_notices.sql index f3d4e10933..b4eb3325b2 100644 --- a/installer/data/mysql/pl-PL/mandatory/sample_notices.sql +++ b/installer/data/mysql/pl-PL/mandatory/sample_notices.sql @@ -397,24 +397,21 @@ Your total unpaid fines are too high. [% ELSE %] The following item, [% biblio.title %], has correctly been renewed and is now due on [% checkout.date_due | $KohaDates as_due_date => 1 %] [% END %]", 'email'); -======= -You have overdues. -[% ELSIF checkout.auto_renew_error == 'auto_too_late' %] -It\'s too late to renew this checkout. -[% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %] -You have too much unpaid fines. -[% END %] -[% ELSE %] -The following item [% biblio.title %] has correctly been renewed and is now due [% checkout.date_due %] -[% END %]", 'email'); -INSERT INTO letter (module, code, name, title, content, message_transport_type) VALUES ('circulation', 'AUTO_RENEWALS_DGST', 'notification on auto renewing', 'Auto renewals (Digest)', +INSERT IGNORE INTO letter (module, code, name, title, content, message_transport_type) VALUES ('circulation', 'AUTO_RENEWALS_DGST', 'notification on auto renewing', 'Auto renewals (Digest)', "Dear [% borrower.firstname %] [% borrower.surname %], -[% IF <> %] -There were <> items that where not correctly renewed. +[% IF error %] + There were [% error %] items that were not correctly renewed. +[% END %] +[% IF success %] + There were [% success %] items that where correctly renewed. [% END %] -[% IF <> %] -There were <> items that where correctly renewed. +[% FOREACH checkout IN checkouts %] + [% checkout.item.biblio.title %] : [% checkout.item.barcode %] + [% IF !checkout.auto_renew_error %] + was renewed until [% checkout.date_due | $KohaDates %] + [% ELSE %] + was not renewed with error: [% checkout.auto_renew_error %] + [% END %] [% END %] -", 'email'); ->>>>>>> Bug 18532: Add new letter AUTO_RENEWALS_DGST, new Auto_Renewals in message_attributes, and configured message_transports:installer/data/mysql/en/mandatory/sample_notices.sql +", 'email'); \ No newline at end of file diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc index 69ec17086e..59adc0e913 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc @@ -13,6 +13,7 @@ [% FOREACH messaging_preference IN messaging_preferences %] + [% NEXT IF messaging_preference.Auto_Renewals && Koha.Preference('AutoRenewalNotices') != 'preferences' %] [% IF ( messaging_preference.Item_Due ) %]Item due [% ELSIF ( messaging_preference.Advance_Notice ) %]Advance notice diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt index 4aaffeda91..843a850cba 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt @@ -45,6 +45,7 @@ [% FOREACH messaging_preference IN messaging_preferences %] + [% NEXT IF messaging_preference.Auto_Renewals && Koha.Preference('AutoRenewalNotices') != 'preferences' %] [% IF ( messaging_preference.Item_Due ) %]Item due [% ELSIF ( messaging_preference.Advance_Notice ) %]Advance notice diff --git a/misc/cronjobs/automatic_renewals.pl b/misc/cronjobs/automatic_renewals.pl index 4fa6fbb833..66c5a29fa8 100755 --- a/misc/cronjobs/automatic_renewals.pl +++ b/misc/cronjobs/automatic_renewals.pl @@ -98,8 +98,8 @@ GetOptions( pod2usage(0) if $help; -my $send_notices_pref = C4::Context->preference('AutoRenewalNotices') -if ( $send_notices_pref = 'cron' ) { +my $send_notices_pref = C4::Context->preference('AutoRenewalNotices'); +if ( $send_notices_pref eq 'cron' ) { warn <<'END_WARN'; The "AutoRenewalNotices" syspref is set to 'Follow the cron switch'. @@ -144,6 +144,8 @@ while ( my $auto_renew = $auto_renews->next ) { $borrower_preferences = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $auto_renew->borrowernumber, message_name => 'auto_renewals' } ) if $send_notices_pref eq 'preferences'; + $send_notices = 1 if !$send_notices && $send_notices_pref eq 'preferences' && $borrower_preferences && $borrower_preferences->{transports} && $borrower_preferences->{transports}->{email}; + # CanBookBeRenewed returns 'auto_renew' when the renewal should be done by this script my ( $ok, $error ) = CanBookBeRenewed( $auto_renew->borrowernumber, $auto_renew->itemnumber ); if ( $error eq 'auto_renew' ) { @@ -155,7 +157,7 @@ while ( my $auto_renew = $auto_renews->next ) { my $date_due = AddRenewal( $auto_renew->borrowernumber, $auto_renew->itemnumber, $auto_renew->branchcode ); $auto_renew->auto_renew_error(undef)->store; } - push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew unless $borrower_preferences && (!$borrower_preferences->{transports} || !$borrower_preferences->{transports}->{email} || $borrower_preferences->{'wants_digest'}); + push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew unless $send_notices_pref ne 'cron' && (!$borrower_preferences || !$borrower_preferences->{transports} || !$borrower_preferences->{transports}->{email} || $borrower_preferences->{'wants_digest'}); } elsif ( $error eq 'too_many' or $error eq 'on_reserve' or $error eq 'restriction' @@ -172,7 +174,7 @@ while ( my $auto_renew = $auto_renews->next ) { if ( not $auto_renew->auto_renew_error or $error ne $auto_renew->auto_renew_error ) { $auto_renew->auto_renew_error($error)->store if $confirm; push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew - if $error ne 'auto_too_soon' && (!$borrower_preferences || ($borrower_preferences->{transports} && $borrower_preferences->{transports}->{email} && !$borrower_preferences->{'wants_digest'})); # Do not notify if it's too soon + if $error ne 'auto_too_soon' && ($send_notices_pref eq 'cron' || ($borrower_preferences && $borrower_preferences->{transports} && $borrower_preferences->{transports}->{email} && !$borrower_preferences->{'wants_digest'})); # Do not notify if it's too soon } } @@ -181,9 +183,11 @@ while ( my $auto_renew = $auto_renews->next ) { if ($digest_per_branch) { $renew_digest->{ $auto_renew->branchcode }->{ $auto_renew->borrowernumber }->{success}++ if $error eq 'auto_renew'; $renew_digest->{ $auto_renew->branchcode }->{ $auto_renew->borrowernumber }->{error}++ unless $error eq 'auto_renew' || $error == 'auto_too_soon' ; + push @{$renew_digest->{ $auto_renew->branchcode }->{ $auto_renew->borrowernumber }->{issues}}, $auto_renew->itemnumber; } else { $renew_digest->{ $auto_renew->borrowernumber }->{success} ++ if $error eq 'auto_renew'; $renew_digest->{ $auto_renew->borrowernumber }->{error}++ unless $error eq 'auto_renew' || $error eq 'auto_too_soon' ; + push @{$renew_digest->{ $auto_renew->borrowernumber }->{issues}}, $auto_renew->itemnumber; } } @@ -292,6 +296,7 @@ sub send_digests { error => $digest->{error}||0, success => $digest->{success}||0, }, + loops => { issues => \@{$digest->{issues}} }, tables => { borrowers => $patron->borrowernumber, }, -- 2.25.0