From 24ae1e02e9f86fa5c9c58e43917be37cbb9b1ff3 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 13 May 2022 16:15:33 +0100 Subject: [PATCH] Bug 30751: Add notice printing to automatic_renewals.pl This patch adds notice preview to the automatic_renewals.pl script. Test plan 1) Setup automtic renewals and add some checkouts with autorenewal enabled 2) Run the automatic_renewals.pl script with verbose mode. (without confirm if your testing and don't want to actually send notice or perform the renewals) 3) Confirm that you no get notices printed at the end of the output Signed-off-by: Lucas Gass --- misc/cronjobs/automatic_renewals.pl | 89 +++++++++++++++++++---------- 1 file changed, 60 insertions(+), 29 deletions(-) diff --git a/misc/cronjobs/automatic_renewals.pl b/misc/cronjobs/automatic_renewals.pl index 1af18c70f5..6a594ed148 100755 --- a/misc/cronjobs/automatic_renewals.pl +++ b/misc/cronjobs/automatic_renewals.pl @@ -215,7 +215,7 @@ while ( my $auto_renew = $auto_renews->next ) { } -if ( $send_notices && $confirm ) { +if ( $send_notices && ( $confirm || $verbose ) ) { for my $borrowernumber ( keys %report ) { my $patron = Koha::Patrons->find($borrowernumber); for my $issue ( @{ $report{$borrowernumber} } ) { @@ -232,32 +232,52 @@ if ( $send_notices && $confirm ) { lang => $patron->lang, ); - my $library = Koha::Libraries->find( $patron->branchcode ); - my $admin_email_address = $library->from_email_address; + if ($verbose) { + say "Would send the following notice to borrowernumber: " + . $patron->borrowernumber; - C4::Letters::EnqueueLetter( - { letter => $letter, - borrowernumber => $borrowernumber, - message_transport_type => 'email', - from_address => $admin_email_address, - } - ); + print $letter->{content}; + } + + if ($confirm) { + my $library = Koha::Libraries->find( $patron->branchcode ); + my $admin_email_address = $library->from_email_address; + + C4::Letters::EnqueueLetter( + { + letter => $letter, + borrowernumber => $borrowernumber, + message_transport_type => 'email', + from_address => $admin_email_address, + } + ); + } } } if ($digest_per_branch) { - while (my ($branchcode, $digests) = each %$renew_digest) { - send_digests({ - digests => $digests, - branchcode => $branchcode, - letter_code => 'AUTO_RENEWALS_DGST', - }); + while ( my ( $branchcode, $digests ) = each %$renew_digest ) { + send_digests( + { + digests => $digests, + branchcode => $branchcode, + letter_code => 'AUTO_RENEWALS_DGST', + confirm => $confirm, + verbose => $verbose + } + ); } - } else { - send_digests({ - digests => $renew_digest, - letter_code => 'AUTO_RENEWALS_DGST', - }); + } + else { + send_digests( + { + digests => $renew_digest, + letter_code => 'AUTO_RENEWALS_DGST', + confirm => $confirm, + verbose => $verbose + + } + ); } } @@ -331,14 +351,25 @@ sub send_digests { ); if ($letter) { - C4::Letters::EnqueueLetter( - { - letter => $letter, - borrowernumber => $borrowernumber, - from_address => $from_address, - message_transport_type => $transport - } - ); + + if ($params->{verbose}) { + say "Would send the following digest notice to borrowernumber: " + . $patron->borrowernumber; + + print $letter->{content}; + } + + if ($params->{confirm}) { + + C4::Letters::EnqueueLetter( + { + letter => $letter, + borrowernumber => $borrowernumber, + from_address => $from_address, + message_transport_type => $transport + } + ); + } } else { warn -- 2.30.2