From 52d30fba7b469c8f879a22af6cb9b0c5643f81ae Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 18 Jan 2016 11:48:14 +0100 Subject: [PATCH] Bug 15543: Use another notice in membership_expiry.pl This patch adds a letter parameter to the cron job membership_expiry. It is used to substitute the default notice by another one. This could be handy if you e.g. send a reminder after the first notice. In any case, it allows for more flexibility. Apart from this new parameter, this patch removes the sub parse_letter from the code. The call to GetPreparedLetter is moved to the for loop and the call to getletter is removed (no longer needed). If there is no letter found, the Letter module already warns you. So we just exit the loop. Test plan: [1] Run membership_expiry.pl -c -n -v -let NOT_EXIST Check if you see a warning (coming from Letters.pm) [2] Check if you have some soon expiring patrons or add before/after parameter to include some. Run membership_expiry.pl -c -n -v [-before ?] [-after ?] [3] Create a new notice MEMBERSHIP2. Copy the text from the original notice and make some adjustments. [4] Run membership_expiry.pl -c -v -let MEMBERSHIP2 [-before ?] [-after ?]. Be aware that this call generates email messages. Verify that the email contained the adjusted text. Signed-off-by: Bernardo Gonzalez Kriegel On top of Bug 14834 Work as described, tested using '-n' to see messages on terminal, e.g. membership_expiry.pl -v -n -c -before 3 -branch BC -after 2 --letter MEMEXP2 No errors Signed-off-by: Kyle M Hall Signed-off-by: Kyle M Hall --- misc/cronjobs/membership_expiry.pl | 70 +++++++++++------------------- 1 file changed, 25 insertions(+), 45 deletions(-) diff --git a/misc/cronjobs/membership_expiry.pl b/misc/cronjobs/membership_expiry.pl index 46c723f35f..36c0329201 100755 --- a/misc/cronjobs/membership_expiry.pl +++ b/misc/cronjobs/membership_expiry.pl @@ -75,6 +75,10 @@ the date set by the preference. Optional parameter to extend the selection with a number of days AFTER the date set by the preference. +=item B<-letter> + +Optional parameter to use another notice than the default one. + =back =head1 CONFIGURATION @@ -134,7 +138,7 @@ my $help = 0; my $man = 0; my $before = 0; my $after = 0; -my $branch; +my ( $branch, $letter_type ); GetOptions( 'help|?' => \$help, @@ -145,6 +149,7 @@ GetOptions( 'branch:s' => \$branch, 'before:i' => \$before, 'after:i' => \$after, + 'letter:s' => \$letter_type, ) or pod2usage(2); pod2usage( -verbose => 2 ) if $man; @@ -167,52 +172,27 @@ warn 'found ' . scalar( @$upcoming_mem_expires ) . ' soon expiring members' if $verbose; # main loop +$letter_type = 'MEMBERSHIP_EXPIRY' if !$letter_type; foreach my $recent ( @$upcoming_mem_expires ) { my $from_address = $recent->{'branchemail'} || $admin_adress; - 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; - - $letter = parse_letter({ - letter => $letter, - borrowernumber => $recent->{'borrowernumber'}, - firstname => $recent->{'firstname'}, - categorycode => $recent->{'categorycode'}, - branchcode => $recent->{'branchcode'}, - }); - if ($letter) { - if ($nomail) { - print $letter->{'content'}."\n"; - } else { - C4::Letters::EnqueueLetter({ - letter => $letter, - borrowernumber => $recent->{'borrowernumber'}, - from_address => $from_address, - message_transport_type => 'email', - }); - } - } -} - -=head1 SUBROUTINES - -=head2 parse_letter - -=cut - -sub parse_letter { - my $params = shift; - foreach my $required ( qw( letter borrowernumber ) ) { - return unless exists $params->{$required}; - } - my $letter = C4::Letters::GetPreparedLetter ( - module => 'members', - letter_code => 'MEMBERSHIP_EXPIRY', - tables => { - 'borrowers', $params->{'borrowernumber'}, - 'branches', $params->{'branchcode'} + my $letter = C4::Letters::GetPreparedLetter( + module => 'members', + letter_code => $letter_type, + branchcode => $recent->{'branchcode'}, + tables => { + borrowers => $recent->{'borrowernumber'}, + branches => $recent->{'branchcode'}, }, ); + last if !$letter; # Letters.pm already warned, just exit + if( $nomail ) { + print $letter->{'content'}."\n"; + } else { + C4::Letters::EnqueueLetter({ + letter => $letter, + borrowernumber => $recent->{'borrowernumber'}, + from_address => $from_address, + message_transport_type => 'email', + }); + } } -- 2.39.5