From 990de2b975e246c077ceee570134bf8a6cc69d79 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 14 May 2020 12:53:30 +0000 Subject: [PATCH] Bug 18532: (follow-up) Remove digest switch and add preference --- .../data/mysql/atomicupdate/bug-18532.perl | 28 +++------------ installer/data/mysql/sysprefs.sql | 1 + .../en/modules/admin/preferences/patrons.pref | 8 +++++ misc/cronjobs/automatic_renewals.pl | 35 ++++++++++++------- 4 files changed, 37 insertions(+), 35 deletions(-) diff --git a/installer/data/mysql/atomicupdate/bug-18532.perl b/installer/data/mysql/atomicupdate/bug-18532.perl index 1e6fb32111..4bb601dd6e 100644 --- a/installer/data/mysql/atomicupdate/bug-18532.perl +++ b/installer/data/mysql/atomicupdate/bug-18532.perl @@ -28,29 +28,6 @@ if( CheckVersion( $DBversion ) ) { (7, 'sms', 1, 'circulation', 'AUTO_RENEWALS_DGST') }); - $dbh->do( qq{ - insert ignore into borrower_message_preferences (categorycode, message_attribute_id, days_in_advance, wants_digest) - select c.categorycode, 7, NULL, 1 - from categories c - left join - borrower_message_preferences p - on c.categorycode = p.categorycode - and p.message_attribute_id = 7 - where p.categorycode is null - - }); - - $dbh->do( qq{ - insert ignore into borrower_message_preferences (borrowernumber, message_attribute_id, days_in_advance, wants_digest) - select b.borrowernumber, 7, NULL, 1 - from borrowers b - left join - borrower_message_preferences p - on b.borrowernumber = p.borrowernumber - and p.message_attribute_id = 7 - where p.borrowernumber is null - }); - $dbh->do( qq{ insert into borrower_message_transport_preferences (borrower_message_preference_id, message_transport_type) select p.borrower_message_preference_id, 'email' @@ -62,6 +39,11 @@ if( CheckVersion( $DBversion ) ) { and t.borrower_message_preference_id is null; }); + $dbh->do(q{ + INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) + VALUES ('AutoRenewalNotices','cron','cron|preferences|never','How should Koha determine whether to end autorenewal notices','Choice') + }); + # Always end with this (adjust the bug info) SetVersion( $DBversion ); print "Upgrade to $DBversion done (Bug 18532 - Add AUTO_RENEWALS in message_attributes and add AUTO_RENEWALS_DGST letter)\n"; diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 4ad73ef827..803fa441d0 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -77,6 +77,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('AutomaticItemReturn','1',NULL,'If ON, Koha will automatically set up a transfer of this item to its homebranch','YesNo'), ('autoMemberNum','0','','If ON, patron number is auto-calculated','YesNo'), ('AutoRemoveOverduesRestrictions','0',NULL,'Defines whether an OVERDUES debarment should be lifted automatically if all overdue items are returned by the patron.','YesNo'), +('AutoRenewalNotices','cron','cron|preferences|never','How should Koha determine whether to end autorenewal notices','Choice'), ('AutoResumeSuspendedHolds','1',NULL,'Allow suspended holds to be automatically resumed by a set date.','YesNo'), ('AutoReturnCheckedOutItems', '0', '', 'If disabled, librarian must confirm return of checked out item when checking out to another.', 'YesNo'), ('AutoSelfCheckAllowed','0','','For corporate and special libraries which want web-based self-check available from any PC without the need for a manual staff login. Most libraries will want to leave this turned off. If on, requires self-check ID and password to be entered in AutoSelfCheckID and AutoSelfCheckPass sysprefs.','YesNo'), 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 991de6668a..6b9dec7af8 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 @@ -168,6 +168,14 @@ Patrons: yes: Enable no: Disable - Send purchase suggestion messages by SMS if no patron email is defined. + - + - "Send automatic renewal notices " + - pref: AutoRenewalNotices + choices: + never: never + preferences: according to patron messaging preferences + cron: (Deprecated) according to cron switch + Patron forms: - - "The following database columns must be filled in on the patron entry screen:" diff --git a/misc/cronjobs/automatic_renewals.pl b/misc/cronjobs/automatic_renewals.pl index ad32c6846e..4fa6fbb833 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 @@ -43,6 +43,8 @@ and the renewal isn't premature (No Renewal before) the issue is renewed. =item B<-s|--send-notices> +DEPRECATED: The system preference AutoRenewalNotices should be used to determine +whether notices are sent or not Send AUTO_RENEWALS notices to patrons if the auto renewal has been done. =item B<-v|--verbose> @@ -53,14 +55,10 @@ Print report to standard out. Without this parameter no changes will be made -=item B<-d|--digest> - -Flag to indicate that this script should process digest messages. - =item B<-b|--digest-per-branch> Flag to indicate that generation of message digests should be -performed separately for each branch. Needs --digest option. +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 @@ -89,18 +87,32 @@ use Koha::Checkouts; use Koha::Libraries; use Koha::Patrons; -my ( $help, $send_notices, $verbose, $confirm, $digest, $digest_per_branch ); +my ( $help, $send_notices, $verbose, $confirm, $digest_per_branch ); GetOptions( 'h|help' => \$help, 's|send-notices' => \$send_notices, 'v|verbose' => \$verbose, 'c|confirm' => \$confirm, - 'd|digest|' => \$digest, 'b|digest-per-branch' => \$digest_per_branch, ) || pod2usage(1); pod2usage(0) if $help; +my $send_notices_pref = C4::Context->preference('AutoRenewalNotices') +if ( $send_notices_pref = 'cron' ) { + warn <<'END_WARN'; + +The "AutoRenewalNotices" syspref is set to 'Follow the cron switch'. +The send_notices switch for this script is deprecated, you should either set the preference +to 'Never send emails' or 'Follow patron messaging preferences' + +END_WARN +} else { + # If not following cron then we should not send if set to never + # and always send any generated according to preferences if following those + $send_notices = $send_notices_pref eq 'never' ? 0 : 1; +} + # 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 @@ -128,10 +140,9 @@ my %report; while ( my $auto_renew = $auto_renews->next ) { print "examining item '" . $auto_renew->itemnumber . "' to auto renew\n" if $verbose; - my $borrower_preferences = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $auto_renew->borrowernumber, - message_name => 'auto_renewals' } ); - - next if !$digest && $borrower_preferences && $borrower_preferences->{'wants_digest'}; + my $borrower_preferences; + $borrower_preferences = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $auto_renew->borrowernumber, + message_name => 'auto_renewals' } ) if $send_notices_pref eq 'preferences'; # CanBookBeRenewed returns 'auto_renew' when the renewal should be done by this script my ( $ok, $error ) = CanBookBeRenewed( $auto_renew->borrowernumber, $auto_renew->itemnumber ); -- 2.25.0