Bugzilla – Attachment 177740 Details for
Bug 32216
Send MEMBERSHIP_EXPIRY notice as print
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 32216: Add print notices to membership_expiry.pl
Bug-32216-Add-print-notices-to-membershipexpirypl.patch (text/plain), 9.34 KB, created by
Jake Deery
on 2025-02-11 15:41:48 UTC
(
hide
)
Description:
Bug 32216: Add print notices to membership_expiry.pl
Filename:
MIME Type:
Creator:
Jake Deery
Created:
2025-02-11 15:41:48 UTC
Size:
9.34 KB
patch
obsolete
>From 0f021f8cd6d416375377f70c761c774cb820f1c1 Mon Sep 17 00:00:00 2001 >From: PerplexedTheta <jahdobble@llownd.net> >Date: Tue, 27 Aug 2024 15:45:06 +0100 >Subject: [PATCH] Bug 32216: Add print notices to membership_expiry.pl > >This patch adds print notice functionality to the membership_expiry.pl script, >by adding both conditional and and forced modes. When passing only --confirm, >the script will check the patron's record for an email address. If one is >found, an email notice is generated. If one is not, a print notice is used >instead. By adding a -p flag, print notices will be generated, even if an >email address is present. > >To test: >a) set the MembershipExpiryDaysNotice syspref to 7 days >b) choose or set up half a dozen patrons with expiry dates > 1) take heed: these expiry dates will need to be T+7 days >c) add fake email addresses to two of the patrons > 1) take heed: the other patrons should have no primary or secondary > email >d) set up the MEMBERSHIP_EXPIRY notice > 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 >e) run ./misc/cronjobs/membership_expiry.pl -n -c > 1) notice how the printed notices contain the word email >f) run ./misc/cronjobs/membership_expiry.pl -c >g) check the notices for the patrons from step b > 1) notice how only email notices are generated >h) APPLY PATCH >i) repeat step e > 1) notice how a mix of email and print notices are now generated >j) run ./misc/cronjobs/membership_expiry.pl -n -p -c > 1) notice how the output is the same as in step i - this is by > design >k) repeat steps f-g > 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 >l) run ./misc/cronjobs/membership_expiry.pl -p -c >m) repeat step g > 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 >n) SIGN OFF > >Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > misc/cronjobs/membership_expiry.pl | 130 +++++++++++++++++++++++------ > 1 file changed, 104 insertions(+), 26 deletions(-) > >diff --git a/misc/cronjobs/membership_expiry.pl b/misc/cronjobs/membership_expiry.pl >index 644e2b505d..cc4c7661e8 100755 >--- a/misc/cronjobs/membership_expiry.pl >+++ b/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 > E<lt>E<lt>thisE<gt>E<gt>. 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; >@@ -186,6 +196,7 @@ GetOptions( > 'man' => \$man, > 'c' => \$confirm, > 'n' => \$nomail, >+ 'p' => \$forceprint, > 'v' => \$verbose, > 'branch:s' => \$branch, > 'before:i' => \$before, >@@ -253,44 +264,111 @@ warn 'found ' . $upcoming_mem_expires->count . ' soon expiring members' > > # main loop > my ( $count_skipped, $count_renewed, $count_enqueued ) = ( 0, 0, 0 ); >-while ( my $expiring_patron = $upcoming_mem_expires->next ) { >- if ( $active && !$expiring_patron->is_active( { months => $active } ) ) { >+while ( my $recent = $upcoming_mem_expires->next ) { >+ 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 && $expiring_patron->is_active( { months => $inactive } ) ) { >+ } elsif ( $inactive && $patron->is_active( { months => $inactive } ) ) { > $count_skipped++; > next; > } > > my $which_notice; > if ($renew) { >- $expiring_patron->renew_account; >+ $patron->renew_account; > $which_notice = $letter_renew; > $count_renewed++; > } else { > $which_notice = $letter_expiry; > } > >- my $from_address = $expiring_patron->library->from_email_address; >- my $letter_params = { >- module => 'members', >- letter_code => $which_notice, >- branchcode => $expiring_patron->branchcode, >- lang => $expiring_patron->lang, >- borrowernumber => $expiring_patron->borrowernumber, >- tables => { >- borrowers => $expiring_patron->borrowernumber, >- branches => $expiring_patron->branchcode, >- }, >- }; >- >- my $sending_params = { >- letter_params => $letter_params, >- message_name => 'Patron_Expiry', >- }; >- >- my $result = $expiring_patron->queue_notice($sending_params); >- $count_enqueued++ if $result->{sent}; >+ 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', >+ } >+ ); >+ } >+ } >+ >+ $count_enqueued++; >+ >+ if ( $patron->smsalertnumber ) { >+ my $sms_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 => 'sms', >+ ); >+ if ($sms_letter) { >+ C4::Letters::EnqueueLetter( >+ { >+ letter => $sms_letter, >+ borrowernumber => $patron->borrowernumber, >+ message_transport_type => 'sms', >+ } >+ ); >+ } >+ } > } > > if ($verbose) { >-- >2.43.0
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 32216
:
170799
|
174975
|
176745
| 177740