Bugzilla – Attachment 98079 Details for
Bug 18532
Messaging preferences for auto renewals
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18532: set auto_renewals as patron messaging preference
Bug-18532-set-autorenewals-as-patron-messaging-pre.patch (text/plain), 11.64 KB, created by
Agustín Moyano
on 2020-01-29 13:34:53 UTC
(
hide
)
Description:
Bug 18532: set auto_renewals as patron messaging preference
Filename:
MIME Type:
Creator:
Agustín Moyano
Created:
2020-01-29 13:34:53 UTC
Size:
11.64 KB
patch
obsolete
>From 377a4e2d682bb3f3dc2b7b11a564108b31ba514d Mon Sep 17 00:00:00 2001 >From: Agustin Moyano <agustinmoyano@theke.io> >Date: Tue, 29 Oct 2019 15:27:38 -0300 >Subject: [PATCH] Bug 18532: set auto_renewals as patron messaging preference > >This patch adds the "Auto renewals" messaging preference on intranet and OPAC, and adds digest feature to misc/cronjobs/automatic_renewals.pl script. > >To test: >1. apply patches >2. perl installer/data/mysql/updatedatabase.pl >3. make sure automatic renewals are allowed in circ rules >4. grab a patron and go to details page >CHECK => patron's messaging preferences has a "Auto renewals" row >5. change autorenewals digest settings and save >6. go to opac with that same patron to "your messaging" option >CHECK => patron's messaging preferences has a "Auto renewals" row, and displays changes made in staff interface. >7. go to patron categories in administration of staff interface and choose a category. >CHECK => in "Default messaging preferences for this patron category" has a "Auto renewals" row >8. set "Auto renewals" messaging preference for a patron and check email and digest. >9. check out an item for that patron, and set it as automatic renewal and set due date as your current date and time >10. perl misc/cronjobs/automatic_renewals.pl --send-notices -v >SUCCESS => item was renewed, and in message_queue table there now should be message of type AUTO_RENEWALS_DGST for the patron >11. Sign off > >Signed-off-by: tgoat <tgoatley@gmail.com> > >Signed-off-by: Kelly McElligott <kelly@bywatersolutions.com> > >Signed-off-by: Kelly McElligott <kelly@bywatersolutions.com> > >Signed-off-by: Marti Fuerst <mfuerst@hmcpl.org> >--- > .../en/includes/messaging-preference-form.inc | 1 + > .../bootstrap/en/modules/opac-messaging.tt | 1 + > misc/cronjobs/automatic_renewals.pl | 160 +++++++++++++++++- > 3 files changed, 156 insertions(+), 6 deletions(-) > >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 2f948c6236..69ec17086e 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 >@@ -20,6 +20,7 @@ > [% ELSIF ( messaging_preference.Hold_Filled ) %]Hold filled > [% ELSIF ( messaging_preference.Item_Check_in ) %]Item check-in > [% ELSIF ( messaging_preference.Item_Checkout ) %]Item checkout >+ [% ELSIF ( messaging_preference.Auto_Renewals ) %]Auto renewals > [% ELSE %]Unknown [% END %]</td> > [% IF ( messaging_preference.takes_days ) %] > <td> >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 3d25f5372f..05a3fe8521 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt >@@ -51,6 +51,7 @@ > [% ELSIF ( messaging_preference.Hold_Filled ) %]Hold filled > [% ELSIF ( messaging_preference.Item_Check_in ) %]Item check-in > [% ELSIF ( messaging_preference.Item_Checkout ) %]Item checkout >+ [% ELSIF ( messaging_preference.Auto_Renewals ) %]Auto renewals > [% ELSE %]Unknown [% END %]</td> > [% IF ( messaging_preference.takes_days ) %] > <td><select class="input-mini" name="[% messaging_preference.message_attribute_id | html %]-DAYS"> >diff --git a/misc/cronjobs/automatic_renewals.pl b/misc/cronjobs/automatic_renewals.pl >index fb1cf03ba9..3fedf457ec 100755 >--- a/misc/cronjobs/automatic_renewals.pl >+++ b/misc/cronjobs/automatic_renewals.pl >@@ -2,7 +2,7 @@ > > # This file is part of Koha. > # >-# Copyright (C) 2014 Hochschule für Gesundheit (hsg), Germany >+# Copyright (C) 2014 Hochschule für Gesundheit (hsg), Germany > # > # Koha is free software; you can redistribute it and/or modify it > # under the terms of the GNU General Public License as published by >@@ -42,7 +42,24 @@ and the renewal isn't premature (No Renewal before) the issue is renewed. > > Send AUTO_RENEWALS notices to patrons if the auto renewal has been done. > >-Note that this option does not support digest yet. >+=item B<-v> >+ >+Verbose. Without this flag set, only fatal errors are reported. >+ >+=item B<--digest-per-branch> >+ >+Flag to indicate that generation of message digests should be >+performed separately for each branch. >+ >+A patron could potentially have loans at several different branches >+There is no natural branch to set as the sender on the aggregated >+message in this situation so the default behavior is to use the >+borrowers home branch. This could surprise to the borrower when >+message sender is a library where they have not borrowed anything. >+ >+Enabling this flag ensures that the issuing library is the sender of >+the digested message. It has no effect unless the borrower has >+chosen 'Digests only' on the advance messages. > > =back > >@@ -62,25 +79,54 @@ use Koha::Libraries; > use Koha::Patrons; > > my ( $help, $send_notices ); >+my $verbose = 0; # -v: verbose >+my $digest_per_branch = 0; # -digest-per-branch: Prepare and send digests per branch > GetOptions( >- 'h|help' => \$help, >- 'send-notices' => \$send_notices, >+ 'h|help' => \$help, >+ 'send-notices' => \$send_notices, >+ 'v' => \$verbose, >+ 'digest-per-branch' => \$digest_per_branch, >+ > ) || pod2usage(1); > > pod2usage(0) if $help; >+ >+# Since advance notice options are not visible in the web-interface >+# unless EnhancedMessagingPreferences is on, let the user know that >+# this script probably isn't going to do much >+if ( ! C4::Context->preference('EnhancedMessagingPreferences') ) { >+ warn <<'END_WARN'; >+ >+The "EnhancedMessagingPreferences" syspref is off. >+Therefore, it is unlikely that this script will actually produce any messages to be sent. >+To change this, edit the "EnhancedMessagingPreferences" syspref. >+ >+END_WARN >+} >+ > cronlogaction(); > >+warn 'getting auto renewals' if $verbose; > my $auto_renews = Koha::Checkouts->search({ auto_renew => 1 }); >+warn 'found ' . $auto_renews->count . ' auto renewals' if $verbose; > >+my $renew_digest = {}; > my %report; > while ( my $auto_renew = $auto_renews->next ) { >+ warn 'examining item "' . $auto_renew->itemnumber . '" to auto renew' if $verbose; >+ >+ my $borrower_preferences = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $auto_renew->borrowernumber, >+ message_name => 'auto_renewals' } ); >+ >+ next unless $borrower_preferences; > > # 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' ) { >+ warn "item renewed" if $verbose; > 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; >+ push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew unless $borrower_preferences->{'wants_digest'}; > } elsif ( $error eq 'too_many' > or $error eq 'on_reserve' > or $error eq 'restriction' >@@ -90,12 +136,24 @@ while ( my $auto_renew = $auto_renews->next ) { > or $error eq 'auto_too_much_oweing' > or $error eq 'auto_too_soon' > or $error eq 'item_denied_renewal' ) { >+ warn "there was an error: $error" if $verbose; > if ( not $auto_renew->auto_renew_error or $error ne $auto_renew->auto_renew_error ) { > $auto_renew->auto_renew_error($error)->store; > push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew >- if $error ne 'auto_too_soon'; # Do not notify if it's too soon >+ if $error ne 'auto_too_soon' && !$borrower_preferences->{'wants_digest'}; # Do not notify if it's too soon > } > } >+ if ( $borrower_preferences->{'wants_digest'} ) { >+ # cache this one to process after we've run through all of the items. >+ 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' ; >+ } 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' ; >+ } >+ } >+ > } > > if ( $send_notices ) { >@@ -127,4 +185,94 @@ if ( $send_notices ) { > ); > } > } >+ >+ if ($digest_per_branch) { >+ while (my ($branchcode, $digests) = each %$renew_digest) { >+ send_digests({ >+ digests => $digests, >+ branchcode => $branchcode, >+ letter_code => 'AUTO_RENEWALS_DGST', >+ }); >+ } >+ } else { >+ send_digests({ >+ digests => $renew_digest, >+ letter_code => 'AUTO_RENEWALS_DGST', >+ }); >+ } > } >+ >+=head1 METHODS >+ >+=head2 send_digests >+ >+ send_digests({ >+ digests => ..., >+ letter_code => ..., >+ }) >+ >+Enqueue digested letters. >+ >+Parameters: >+ >+=over 4 >+ >+=item C<$digests> >+ >+Reference to the array of digested messages. >+ >+=item C<$letter_code> >+ >+String that denote the letter code. >+ >+=back >+ >+=cut >+ >+sub send_digests { >+ my $params = shift; >+ >+ my $admin_email_address = C4::Context->preference('KohaAdminEmailAddress'); >+ >+ PATRON: while ( my ( $borrowernumber, $digest ) = each %{$params->{digests}} ) { >+ my $borrower_preferences = >+ C4::Members::Messaging::GetMessagingPreferences( >+ { >+ borrowernumber => $borrowernumber, >+ message_name => 'auto_renewals' >+ } >+ ); >+ >+ next PATRON unless $borrower_preferences; # how could this happen? >+ >+ my $patron = Koha::Patrons->find( $borrowernumber ); >+ my $library = Koha::Libraries->find( $params->{branchcode} ); >+ my $from_address = $library->{branchemail} || $admin_email_address; >+ >+ foreach my $transport ( keys %{ $borrower_preferences->{'transports'} } ) { >+ my $letter = C4::Letters::GetPreparedLetter ( >+ module => 'circulation', >+ letter_code => $params->{letter_code}, >+ branchcode => $params->{branchcode}, >+ lang => $patron->lang, >+ substitute => { >+ error => $digest->{error}||0, >+ success => $digest->{success}||0, >+ }, >+ tables => { >+ borrowers => $patron->borrowernumber, >+ }, >+ message_transport_type => $transport, >+ ) || warn "no letter of type '$params->{letter_code}' found for borrowernumber $borrowernumber. Please see sample_notices.sql"; >+ >+ next unless $letter; >+ >+ C4::Letters::EnqueueLetter({ >+ letter => $letter, >+ borrowernumber => $borrowernumber, >+ from_address => $from_address, >+ message_transport_type => $transport >+ }); >+ } >+ } >+} >\ No newline at end of file >-- >2.17.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18532
:
95030
|
95031
|
95337
|
95338
|
95456
|
96049
|
96050
|
96487
|
96494
|
96495
|
98078
|
98079
|
99193
|
99194
|
104880
|
104881
|
104882
|
104883
|
105500
|
105501
|
105502
|
105503
|
114316
|
115798
|
115799
|
115800
|
115801
|
115802
|
115829
|
115830
|
115831
|
115832
|
115833
|
118198
|
118199
|
118205
|
118318
|
118329
|
118330
|
118331
|
118356