From 6fd043691f9add898dde3aadc02481df83969ff6 Mon Sep 17 00:00:00 2001 From: Amit Gupta Date: Fri, 26 Jun 2015 10:52:01 +0530 Subject: [PATCH] Bug 6810: Squashed Amit Gupta's patches Amit added these fixes which were not signed off yet, so I squashed them for simplicity. -- Mark Tompsett Bug 6810 - Fix QA failures - remove DateTime->now() - use Koha::DateUtils->dt_from_string; - use Pod2usage for the usage - use Modern::Perl - use branches table - Change letter code from MEMEXP to MEMBERSHIP_EXPIRY Bug 6810 - Fix QA failures - MembershipExpiryDaysNotice system preferences arragned alphabetical order. Bug 6810 - Add sample notices --- C4/Members.pm | 6 +- .../bug_6810-add_membershipexpiry_notification.sql | 1 + .../data/mysql/de-DE/mandatory/sample_notices.sql | 5 +- .../data/mysql/en/mandatory/sample_notices.sql | 3 + .../data/mysql/es-ES/mandatory/sample_notices.sql | 5 +- .../mysql/fr-FR/1-Obligatoire/sample_notices.sql | 5 +- installer/data/mysql/it-IT/necessari/notices.sql | 5 +- .../mysql/nb-NO/1-Obligatorisk/sample_notices.sql | 5 +- .../data/mysql/pl-PL/mandatory/sample_notices.sql | 5 +- .../data/mysql/ru-RU/mandatory/sample_notices.sql | 5 +- installer/data/mysql/sysprefs.sql | 4 +- .../data/mysql/uk-UA/mandatory/sample_notices.sql | 5 +- misc/cronjobs/membership_expiry.pl | 127 ++++++++++++++++++--- 13 files changed, 155 insertions(+), 26 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_6810-add_membershipexpiry_notification.sql diff --git a/C4/Members.pm b/C4/Members.pm index b0bd3be..3db6e09 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -42,6 +42,8 @@ use Text::Unaccent qw( unac_string ); use Koha::AuthUtils qw(hash_password); use Koha::Database; use Module::Load; +use DateTime::Duration; + if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) { load Koha::NorwegianPatronDB, qw( NLUpdateHashedPIN NLEncryptPIN NLSync ); } @@ -1489,8 +1491,8 @@ sub GetExpiryDate { sub GetUpcomingMembershipExpires { my $dbh = C4::Context->dbh; - my $days = C4::Context->preference("MembershipExpiryDaysNotice") || 0; - my $dateexpiry = DateTime->now()->add(days => $days)->ymd(); + my $days = DateTime::Duration->new(days => C4::Context->preference("MembershipExpiryDaysNotice") || 0); + my $dateexpiry = output_pref({ dt => (dt_from_string() + $days), dateformat => 'iso', dateonly => 1 }); my $query = " SELECT borrowers.*, categories.description, diff --git a/installer/data/mysql/atomicupdate/bug_6810-add_membershipexpiry_notification.sql b/installer/data/mysql/atomicupdate/bug_6810-add_membershipexpiry_notification.sql new file mode 100644 index 0000000..6c8438d --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_6810-add_membershipexpiry_notification.sql @@ -0,0 +1 @@ +INSERT IGNORE INTO letter (module, code, name, title,content) VALUES('members','MEMBERSHIP_EXPIRY','Account expiration','Account expiration','Dear <> <> <>,\r\n\r\nYour library card will expire soon, on:\r\n\r\n<>\r\n\r\nThank you,\r\n\r\nLibrarian\r\n\r\n<>'); diff --git a/installer/data/mysql/de-DE/mandatory/sample_notices.sql b/installer/data/mysql/de-DE/mandatory/sample_notices.sql index bae68ff..12a6b68 100644 --- a/installer/data/mysql/de-DE/mandatory/sample_notices.sql +++ b/installer/data/mysql/de-DE/mandatory/sample_notices.sql @@ -135,4 +135,7 @@ Ihr Biblioheksteam' ); INSERT INTO letter(module, code, branchcode, name, title, content, message_transport_type) -VALUES ('acquisition', 'ACQ_NOTIF_ON_RECEIV', '', 'Benachrichtigung bei Zugang', 'Bestelltes Medium ist eingetroffen', 'Liebe/r <> <>,\n\nDie Bestellung <> (<>) ist eingetroffen und wird bearbeitet.\n\nIhr Bibliotheksteam', 'email') +VALUES ('acquisition', 'ACQ_NOTIF_ON_RECEIV', '', 'Benachrichtigung bei Zugang', 'Bestelltes Medium ist eingetroffen', 'Liebe/r <> <>,\n\nDie Bestellung <> (<>) ist eingetroffen und wird bearbeitet.\n\nIhr Bibliotheksteam', 'email'); + +INSERT INTO letter(module, code, branchcode, name, title, is_html, content) +VALUES ('members','MEMBERSHIP_EXPIRY','','Account expiration','Account expiration', '0', 'Dear <> <> <>,.\r\n\r\nYour library card will expire soon, on:\r\n\r\n<>\r\n\r\nThank you,\r\n\r\nLibrarian\r\n\r\n<>'); diff --git a/installer/data/mysql/en/mandatory/sample_notices.sql b/installer/data/mysql/en/mandatory/sample_notices.sql index 35625dd..488498b 100644 --- a/installer/data/mysql/en/mandatory/sample_notices.sql +++ b/installer/data/mysql/en/mandatory/sample_notices.sql @@ -155,3 +155,6 @@ Your library.' INSERT INTO letter(module, code, branchcode, name, title, content, message_transport_type) VALUES ('acquisition', 'ACQ_NOTIF_ON_RECEIV', '', 'Notification on receiving', 'Order received', 'Dear <> <>,\n\n The order <> (<>) has been received.\n\nYour library.', 'email') + +INSERT INTO letter(module, code, branchcode, name, title, is_html, content) +VALUES ('members','MEMBERSHIP_EXPIRY','','Account expiration','Account expiration', '0', 'Dear <> <> <>,.\r\n\r\nYour library card will expire soon, on:\r\n\r\n<>\r\n\r\nThank you,\r\n\r\nLibrarian\r\n\r\n<>'); diff --git a/installer/data/mysql/es-ES/mandatory/sample_notices.sql b/installer/data/mysql/es-ES/mandatory/sample_notices.sql index d8dbaab..06218c2 100644 --- a/installer/data/mysql/es-ES/mandatory/sample_notices.sql +++ b/installer/data/mysql/es-ES/mandatory/sample_notices.sql @@ -149,4 +149,7 @@ Your library.' INSERT INTO letter(module, code, branchcode, name, title, content, message_transport_type) -VALUES ('acquisition', 'ACQ_NOTIF_ON_RECEIV', '', 'Notification on receiving', 'Order received', 'Dear <> <>,\n\n The order <> (<>) has been received.\n\nYour library.', 'email') +VALUES ('acquisition', 'ACQ_NOTIF_ON_RECEIV', '', 'Notification on receiving', 'Order received', 'Dear <> <>,\n\n The order <> (<>) has been received.\n\nYour library.', 'email'); + +INSERT INTO letter(module, code, branchcode, name, title, is_html, content) +VALUES ('members','MEMBERSHIP_EXPIRY','','Account expiration','Account expiration', '0', 'Dear <> <> <>,.\r\n\r\nYour library card will expire soon, on:\r\n\r\n<>\r\n\r\nThank you,\r\n\r\nLibrarian\r\n\r\n<>'); diff --git a/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql b/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql index bdf7b52..05a707f 100644 --- a/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql +++ b/installer/data/mysql/fr-FR/1-Obligatoire/sample_notices.sql @@ -150,4 +150,7 @@ Your library.' ); INSERT INTO letter(module, code, branchcode, name, title, content, message_transport_type) -VALUES ('acquisition', 'ACQ_NOTIF_ON_RECEIV', '', 'Notification on receiving', 'Order received', 'Dear <> <>,\n\n The order <> (<>) has been received.\n\nYour library.', 'email') +VALUES ('acquisition', 'ACQ_NOTIF_ON_RECEIV', '', 'Notification on receiving', 'Order received', 'Dear <> <>,\n\n The order <> (<>) has been received.\n\nYour library.', 'email'); + +INSERT INTO letter(module, code, branchcode, name, title, is_html, content) +VALUES ('members','MEMBERSHIP_EXPIRY','','Account expiration','Account expiration', '0', 'Dear <> <> <>,.\r\n\r\nYour library card will expire soon, on:\r\n\r\n<>\r\n\r\nThank you,\r\n\r\nLibrarian\r\n\r\n<>'); diff --git a/installer/data/mysql/it-IT/necessari/notices.sql b/installer/data/mysql/it-IT/necessari/notices.sql index f52452d..f1f598f 100644 --- a/installer/data/mysql/it-IT/necessari/notices.sql +++ b/installer/data/mysql/it-IT/necessari/notices.sql @@ -147,4 +147,7 @@ Lo staff della biblioteca.' ); INSERT INTO letter(module, code, branchcode, name, title, content, message_transport_type) -VALUES ('acquisition', 'ACQ_NOTIF_ON_RECEIV', '', 'Notification on receiving', 'Order received', 'Dear <> <>,\n\n The order <> (<>) has been received.\n\nYour library.', 'email') +VALUES ('acquisition', 'ACQ_NOTIF_ON_RECEIV', '', 'Notification on receiving', 'Order received', 'Dear <> <>,\n\n The order <> (<>) has been received.\n\nYour library.', 'email'); + +INSERT INTO letter(module, code, branchcode, name, title, is_html, content) +VALUES ('members','MEMBERSHIP_EXPIRY','','Account expiration','Account expiration', '0', 'Dear <> <> <>,.\r\n\r\nYour library card will expire soon, on:\r\n\r\n<>\r\n\r\nThank you,\r\n\r\nLibrarian\r\n\r\n<>'); diff --git a/installer/data/mysql/nb-NO/1-Obligatorisk/sample_notices.sql b/installer/data/mysql/nb-NO/1-Obligatorisk/sample_notices.sql index 2c2c904..8b6fadc 100644 --- a/installer/data/mysql/nb-NO/1-Obligatorisk/sample_notices.sql +++ b/installer/data/mysql/nb-NO/1-Obligatorisk/sample_notices.sql @@ -169,4 +169,7 @@ Your library.' ); INSERT INTO letter(module, code, branchcode, name, title, content, message_transport_type) -VALUES ('acquisition', 'ACQ_NOTIF_ON_RECEIV', '', 'Notification on receiving', 'Order received', 'Dear <> <>,\n\n The order <> (<>) has been received.\n\nYour library.', 'email') +VALUES ('acquisition', 'ACQ_NOTIF_ON_RECEIV', '', 'Notification on receiving', 'Order received', 'Dear <> <>,\n\n The order <> (<>) has been received.\n\nYour library.', 'email'); + +INSERT INTO letter(module, code, branchcode, name, title, is_html, content) +VALUES ('members','MEMBERSHIP_EXPIRY','','Account expiration','Account expiration', '0', 'Dear <> <> <>,.\r\n\r\nYour library card will expire soon, on:\r\n\r\n<>\r\n\r\nThank you,\r\n\r\nLibrarian\r\n\r\n<>'); diff --git a/installer/data/mysql/pl-PL/mandatory/sample_notices.sql b/installer/data/mysql/pl-PL/mandatory/sample_notices.sql index 64f965d..96fc6ce 100644 --- a/installer/data/mysql/pl-PL/mandatory/sample_notices.sql +++ b/installer/data/mysql/pl-PL/mandatory/sample_notices.sql @@ -147,4 +147,7 @@ Your library.' ); INSERT INTO letter(module, code, branchcode, name, title, content, message_transport_type) -VALUES ('acquisition', 'ACQ_NOTIF_ON_RECEIV', '', 'Notification on receiving', 'Order received', 'Dear <> <>,\n\n The order <> (<>) has been received.\n\nYour library.', 'email') +VALUES ('acquisition', 'ACQ_NOTIF_ON_RECEIV', '', 'Notification on receiving', 'Order received', 'Dear <> <>,\n\n The order <> (<>) has been received.\n\nYour library.', 'email'); + +INSERT INTO letter(module, code, branchcode, name, title, is_html, content) +VALUES ('members','MEMBERSHIP_EXPIRY','','Account expiration','Account expiration', '0', 'Dear <> <> <>,.\r\n\r\nYour library card will expire soon, on:\r\n\r\n<>\r\n\r\nThank you,\r\n\r\nLibrarian\r\n\r\n<>'); diff --git a/installer/data/mysql/ru-RU/mandatory/sample_notices.sql b/installer/data/mysql/ru-RU/mandatory/sample_notices.sql index 55cc828..440aac6 100644 --- a/installer/data/mysql/ru-RU/mandatory/sample_notices.sql +++ b/installer/data/mysql/ru-RU/mandatory/sample_notices.sql @@ -149,4 +149,7 @@ Your library.' ); INSERT INTO letter(module, code, branchcode, name, title, content, message_transport_type) -VALUES ('acquisition', 'ACQ_NOTIF_ON_RECEIV', '', 'Notification on receiving', 'Order received', 'Dear <> <>,\n\n The order <> (<>) has been received.\n\nYour library.', 'email') +VALUES ('acquisition', 'ACQ_NOTIF_ON_RECEIV', '', 'Notification on receiving', 'Order received', 'Dear <> <>,\n\n The order <> (<>) has been received.\n\nYour library.', 'email'); + +INSERT INTO letter(module, code, branchcode, name, title, is_html, content) +VALUES ('members','MEMBERSHIP_EXPIRY','','Account expiration','Account expiration', '0', 'Dear <> <> <>,.\r\n\r\nYour library card will expire soon, on:\r\n\r\n<>\r\n\r\nThank you,\r\n\r\nLibrarian\r\n\r\n<>'); diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 04cdb9b..b69a0d8 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -207,6 +207,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('maxoutstanding','5','','maximum amount withstanding to be able make holds','Integer'), ('maxRecordsForFacets','20',NULL,NULL,'Integer'), ('maxreserves','50','','Define maximum number of holds a patron can place','Integer'), +('MembershipExpiryDaysNotice','14','Send an account expiration notice that a patron\'s card is about to expire after',NULL,'Integer'), ('minPasswordLength','3',NULL,'Specify the minimum length of a patron/staff password','free'), ('NewItemsDefaultLocation','','','If set, all new items will have a location of the given Location Code ( Authorized Value type LOC )',''), ('noissuescharge','5','','Define maximum amount withstanding before check outs are blocked','Integer'), @@ -480,6 +481,5 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('XSLTDetailsDisplay','default','','Enable XSL stylesheet control over details page display on intranet','Free'), ('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'), ('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'), -('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo'), -('MembershipExpiryDaysNotice' ,14,'Send an account expiration notice that a patron\'s card is about to expire after',NULL,'Integer') +('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo') ; diff --git a/installer/data/mysql/uk-UA/mandatory/sample_notices.sql b/installer/data/mysql/uk-UA/mandatory/sample_notices.sql index 59f517b..fd83e47 100644 --- a/installer/data/mysql/uk-UA/mandatory/sample_notices.sql +++ b/installer/data/mysql/uk-UA/mandatory/sample_notices.sql @@ -148,4 +148,7 @@ Your library.' ); INSERT INTO letter(module, code, branchcode, name, title, content, message_transport_type) -VALUES ('acquisition', 'ACQ_NOTIF_ON_RECEIV', '', 'Notification on receiving', 'Order received', 'Dear <> <>,\n\n The order <> (<>) has been received.\n\nYour library.', 'email') +VALUES ('acquisition', 'ACQ_NOTIF_ON_RECEIV', '', 'Notification on receiving', 'Order received', 'Dear <> <>,\n\n The order <> (<>) has been received.\n\nYour library.', 'email'); + +INSERT INTO letter(module, code, branchcode, name, title, is_html, content) +VALUES ('members','MEMBERSHIP_EXPIRY','','Account expiration','Account expiration', '0', 'Dear <> <> <>,.\r\n\r\nYour library card will expire soon, on:\r\n\r\n<>\r\n\r\nThank you,\r\n\r\nLibrarian\r\n\r\n<>'); diff --git a/misc/cronjobs/membership_expiry.pl b/misc/cronjobs/membership_expiry.pl index f92b77f..11a32ad 100755 --- a/misc/cronjobs/membership_expiry.pl +++ b/misc/cronjobs/membership_expiry.pl @@ -2,7 +2,7 @@ # This file is part of Koha. # -# Copyright (C) 2013 Amit Gupta (amitddng135@gmail.com) +# Copyright (C) 2015 Amit Gupta (amitddng135@gmail.com) # # Koha is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -19,21 +19,28 @@ =head1 NAME -membership_expires.pl - cron script to put membership expiry reminders into message queue +membership_expiry.pl - cron script to put memberships expires reminders into message queue =head1 SYNOPSIS -./membership_expires.pl -c +./membership_expiry.pl -c or, in crontab: -0 1 * * * membership_expires.pl -c +0 1 * * * membership_expiry.pl -c + +=head1 DESCRIPTION + +This script send memberships expires reminder notices to be sent to +patrons. It queues them in the message queue, which is processed by +the process_message_queue.pl cronjob. =cut -use strict; -use warnings; + +use Modern::Perl; use Getopt::Long; +use Pod::Usage; use Data::Dumper; BEGIN { # find Koha's Perl modules @@ -47,18 +54,109 @@ use C4::Letters; use C4::Dates qw/format_date/; use C4::Log; -cronlogaction(); + +=head1 NAME + +membership_expiry.pl - prepare messages to be sent to patrons for nearly memberships are going expires + +=head1 SYNOPSIS + +membership_expiry.pl [-c] + +=head1 OPTIONS + +=over 8 + +=item B<--help> + +Print a brief help message and exits. + +=item B<--man> + +Prints the manual page and exits. + +=item B<-v> + +Verbose. Without this flag set, only fatal errors are reported. + +=item B<-n> + +Do not send any email. Memberships expires notices that would have been sent to +the patrons are printed to standard out. + +=item B<-c> + +Confirm flag: Add this option. The script will only print a usage +statement otherwise. + +=back + +=head1 DESCRIPTION + +This script is designed to alert send memberships expires notice + +=head2 Configuration + +This script pays attention to send the memberships expires notice +The content of the messages is configured in Tools -> Notices and slips. Use the MEMBERSHIP_EXPIRY template + +=head2 Outgoing emails + +Typically, messages are prepared for each patron when the memberships are going to expires + + +These emails are staged in the outgoing message queue, as are messages +produced by other features of Koha. This message queue must be +processed regularly by the +F program. + +In the event that the C<-n> flag is passed to this program, no emails +are sent. Instead, messages are sent on standard output from this +program. + +=head2 Templates + +Templates can contain variables enclosed in double angle brackets like +EEthisEE. Those variables will be replaced with values +specific to the members there membership expiry date is coming. +Available variables are: + +=over + +=item EEborrowers.*EE + +any field from the borrowers table + +=item EEbranches.*EE + +any field from the branches table + +=back + +=head1 SEE ALSO + +The F program allows you to send +messages to patrons when the memberships are going to expires. +=cut # These are defaults for command line options. + my $confirm; # -c: Confirm that the user has read and configured this script. my $nomail; # -n: No mail. Will not send any emails. my $verbose= 0; # -v: verbose -GetOptions( 'c' => \$confirm, +my $help = 0; +my $man = 0; + +GetOptions( + 'help|?' => \$help, + 'man' => \$man, + 'c' => \$confirm, 'n' => \$nomail, 'v' => \$verbose, - ); - + ) or pod2usage(2); +pod2usage(1) if $help; +pod2usage( -verbose => 2 ) if $man;; my $usage = << 'ENDUSAGE'; This script prepares for membership expiry reminders to be sent to @@ -78,6 +176,8 @@ unless ($confirm) { exit unless (/^y/i); } +cronlogaction(); + my $admin_adress = C4::Context->preference('KohaAdminEmailAddress'); warn 'getting upcoming membership expires' if $verbose; my $upcoming_mem_expires = C4::Members::GetUpcomingMembershipExpires(); @@ -86,7 +186,7 @@ warn 'found ' . scalar( @$upcoming_mem_expires ) . ' issues' if $verbose; UPCOMINGMEMEXP: foreach my $recent ( @$upcoming_mem_expires ) { my $from_address = $recent->{'branchemail'} || $admin_adress; - my $letter_type = 'MEMEXP'; + my $letter_type = 'MEMBERSHIP_EXPIRY'; my $letter = C4::Letters::getletter( 'members', $letter_type, $recent->{'branchcode'} ); die "no letter of type '$letter_type' found. Please see sample_notices.sql" unless $letter; @@ -123,9 +223,8 @@ sub parse_letter { } my $letter = C4::Letters::GetPreparedLetter ( module => 'members', - letter_code => 'MEMEXP', - branchcode => $params->{'branchcode'}, - tables => {'borrowers', $params->{'borrowernumber'},}, + letter_code => 'MEMBERSHIP_EXPIRY', + tables => {'borrowers', $params->{'borrowernumber'}, 'branches', $params->{'branchcode'}}, ); } -- 2.1.4