@@ -, +, @@ 1) take heed: these expiry dates will need to be T+7 days 1) take heed: the other patrons should have no primary or secondary email a) set content & subject in the email notice to contain the word email b) set content & subject in the print notice to contain the word print 1) notice how the printed notices contain the word email 1) notice how only email notices are generated 1) notice how a mix of email and print notices are now generated 1) notice how the output is the same as in step i - this is by design 1) notice how some patrons will only get an email notice, whilst others will only get a print notice 2) this should occur based on which patrons do, or do not have a valid primary or secondary email 1) notice that all patrons now get a print notice, whilst some get both a print notice, and an email notice. Again, this should occur based on whether the patron has a valid primary or secondary email --- misc/cronjobs/membership_expiry.pl | 121 ++++++++++++++++++++--------- 1 file changed, 86 insertions(+), 35 deletions(-) --- a/misc/cronjobs/membership_expiry.pl +++ a/misc/cronjobs/membership_expiry.pl @@ -24,7 +24,7 @@ membership_expiry.pl - cron script to put membership expiry reminders into the m =head1 SYNOPSIS -./membership_expiry.pl -c [-v] [-n] [-branch CODE] [-before DAYS] [-after DAYS] [-where COND] [-renew] [-letter X] [-letter-renew Y] [-active|-inactive] +./membership_expiry.pl -c [-v] [-n] [-p] [-branch CODE] [-before DAYS] [-after DAYS] [-where COND] [-renew] [-letter X] [-letter-renew Y] [-active|-inactive] or, in crontab: @@ -54,9 +54,14 @@ Verbose. Without this flag set, only fatal errors are reported. =item B<-n> -Do not send any email. Membership expire notices that would have been sent to +Do not send any notices. Membership expire notices that would have been sent to the patrons are printed to standard out. +=item B<-p> + +Force the generation of print notices, even if the borrower has an email address. +Note that this flag cannot be used in combination with -n + =item B<-c> Confirm flag: Add this option. The script will only print a usage @@ -132,6 +137,10 @@ 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. +When using the C<-p> flag, print notices are generated regardless of whether or +not the borrower has an email address. This can be useful for libraries that +prefer to deal with print notices. + Notices can contain variables enclosed in double angle brackets like EEthisEE. Those variables will be replaced with values specific to the soon expiring members. @@ -165,6 +174,7 @@ use Koha::Patrons; # 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 $forceprint; # -p: Force print notices, even if email is found my $verbose = 0; # -v: verbose my $help = 0; my $man = 0; @@ -185,6 +195,7 @@ GetOptions( 'man' => \$man, 'c' => \$confirm, 'n' => \$nomail, + 'p' => \$forceprint, 'v' => \$verbose, 'branch:s' => \$branch, 'before:i' => \$before, @@ -254,64 +265,104 @@ warn 'found ' . $upcoming_mem_expires->count . ' soon expiring members' # main loop my ( $count_skipped, $count_renewed, $count_enqueued ) = ( 0, 0, 0 ); while ( my $recent = $upcoming_mem_expires->next ) { - if ( $active && !$recent->is_active( { months => $active } ) ) { + my $patron = Koha::Patrons->find( $recent->borrowernumber ); + my $user_email = $patron->notice_email_address; + my $from_address = $patron->library->from_email_address; + + if ( $active && !$patron->is_active( { months => $active } ) ) { $count_skipped++; next; - } elsif ( $inactive && $recent->is_active( { months => $inactive } ) ) { + } elsif ( $inactive && $patron->is_active( { months => $inactive } ) ) { $count_skipped++; next; } my $which_notice; if ($renew) { - $recent->renew_account; + $patron->renew_account; $which_notice = $letter_renew; $count_renewed++; } else { $which_notice = $letter_expiry; } - my $from_address = $recent->library->from_email_address; - my $letter = C4::Letters::GetPreparedLetter( - module => 'members', - letter_code => $which_notice, - branchcode => $recent->branchcode, - lang => $recent->lang, - tables => { - borrowers => $recent->borrowernumber, - branches => $recent->branchcode, - }, - ); - last if !$letter; # Letters.pm already warned, just exit - if ($nomail) { - print $letter->{'content'}."\n"; - next; + if ($user_email) { + my $email_letter = C4::Letters::GetPreparedLetter( + module => 'members', + letter_code => $which_notice, + branchcode => $patron->branchcode, + lang => $patron->lang, + tables => { + borrowers => $patron->borrowernumber, + branches => $patron->branchcode, + }, + message_transport_type => 'email', + ); + + if ($nomail) { + print $email_letter->{'content'} . "\n"; + next; + } + + if ($email_letter) { + C4::Letters::EnqueueLetter( + { + letter => $email_letter, + borrowernumber => $patron->borrowernumber, + from_address => $from_address, + message_transport_type => 'email', + } + ); + } + } + + if ( !$user_email || $forceprint ) { + my $print_letter = C4::Letters::GetPreparedLetter( + module => 'members', + letter_code => $which_notice, + branchcode => $patron->branchcode, + lang => $patron->lang, + tables => { + borrowers => $patron->borrowernumber, + branches => $patron->branchcode, + }, + message_transport_type => 'print', + ); + + if ($nomail) { + print $print_letter->{'content'} . "\n"; + next; + } + + if ($print_letter) { + C4::Letters::EnqueueLetter( + { + letter => $print_letter, + borrowernumber => $patron->borrowernumber, + message_transport_type => 'print', + } + ); + } } - C4::Letters::EnqueueLetter({ - letter => $letter, - borrowernumber => $recent->borrowernumber, - from_address => $from_address, - message_transport_type => 'email', - }); $count_enqueued++; - if ($recent->smsalertnumber) { - my $smsletter = C4::Letters::GetPreparedLetter( + if ($patron->smsalertnumber) { + my $sms_letter = C4::Letters::GetPreparedLetter( module => 'members', letter_code => $which_notice, - branchcode => $recent->branchcode, - lang => $recent->lang, + branchcode => $patron->branchcode, + lang => $patron->lang, tables => { - borrowers => $recent->borrowernumber, - branches => $recent->branchcode, + borrowers => $patron->borrowernumber, + branches => $patron->branchcode, }, message_transport_type => 'sms', ); - if ($smsletter) { + if ($sms_letter) { C4::Letters::EnqueueLetter({ - letter => $smsletter, - borrowernumber => $recent->borrowernumber, + letter => $sms_letter, + borrowernumber => $patron->borrowernumber, message_transport_type => 'sms', }); } --