From 14896e2032cccd833f74c251121aabc5da471715 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 Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- .../data/mysql/atomicupdate/bug-18532.perl | 28 +++------------- installer/data/mysql/mandatory/sysprefs.sql | 1 + .../en/modules/admin/preferences/patrons.pref | 7 ++++ misc/cronjobs/automatic_renewals.pl | 33 ++++++++++++------- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/installer/data/mysql/atomicupdate/bug-18532.perl b/installer/data/mysql/atomicupdate/bug-18532.perl index 770b129b58..1308bab19e 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,5 +39,10 @@ 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') + }); + NewVersion( $DBversion, 18532, 'Messaging preferences for auto renewals' ); } diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 3ead03b283..b513bd37bd 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -78,6 +78,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 0792cba7c7..21235e9ee5 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 @@ -191,6 +191,13 @@ Patrons: 1: Enable 0: Disable - sending 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 a02bdf9c16..3b66381cc2 100755 --- a/misc/cronjobs/automatic_renewals.pl +++ b/misc/cronjobs/automatic_renewals.pl @@ -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, undef, 1 ); -- 2.39.5