From 6e0a4d18d4f5c996c18b719f020adcfb800368b8 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 28 Jan 2020 14:27:06 +0000 Subject: [PATCH] Bug 24526: Add verbose and commit options to automatic_renewals cronjob To test: 1 - Apply patch 2 - Have some items marked for auto-renewal 3 - Run the job with no parameters 4 - It should print 'Test mode' 5 - Provide -v 6 - It should print 'Test mode' then a line for each item 7 - Provide -v -c 8 - It should not say test mode, but should provide a line for each item 9 - Provide -c 10 - Shoudl run as expected with no output Signed-off-by: David Nind Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize --- misc/cronjobs/automatic_renewals.pl | 30 ++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/misc/cronjobs/automatic_renewals.pl b/misc/cronjobs/automatic_renewals.pl index fb1cf03ba9..547100afb8 100755 --- a/misc/cronjobs/automatic_renewals.pl +++ b/misc/cronjobs/automatic_renewals.pl @@ -44,6 +44,14 @@ Send AUTO_RENEWALS notices to patrons if the auto renewal has been done. Note that this option does not support digest yet. +=item B<--verbose> + +Print report to standard out. + +=item B<--commit> + +Without this parameter no changes will be made + =back =cut @@ -61,10 +69,12 @@ use Koha::Checkouts; use Koha::Libraries; use Koha::Patrons; -my ( $help, $send_notices ); +my ( $help, $send_notices, $verbose, $commit ); GetOptions( 'h|help' => \$help, 'send-notices' => \$send_notices, + 'v|verbose' => \$verbose, + 'c|commit' => \$commit, ) || pod2usage(1); pod2usage(0) if $help; @@ -73,13 +83,18 @@ cronlogaction(); my $auto_renews = Koha::Checkouts->search({ auto_renew => 1 }); my %report; +print "Test run only\n" unless $commit; while ( my $auto_renew = $auto_renews->next ) { # CanBookBeRenewed returns 'auto_renew' when the renewal should be done by this script my ( $ok, $error ) = CanBookBeRenewed( $auto_renew->borrowernumber, $auto_renew->itemnumber ); if ( $error eq 'auto_renew' ) { - my $date_due = AddRenewal( $auto_renew->borrowernumber, $auto_renew->itemnumber, $auto_renew->branchcode ); - $auto_renew->auto_renew_error(undef)->store; + if ($commit){ + my $date_due = AddRenewal( $auto_renew->borrowernumber, $auto_renew->itemnumber, $auto_renew->branchcode ); + $auto_renew->auto_renew_error(undef)->store; + } + $verbose && print "Issue id: " . $auto_renew->issue_id . " for borrower: " . $auto_renew->borrowernumber . " and item: " . $auto_renew->itemnumber; + $verbose && $commit ? print " will be renewed.\n" : print " would be renewed.\n"; push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew; } elsif ( $error eq 'too_many' or $error eq 'on_reserve' @@ -90,8 +105,13 @@ while ( my $auto_renew = $auto_renews->next ) { or $error eq 'auto_too_much_oweing' or $error eq 'auto_too_soon' or $error eq 'item_denied_renewal' ) { + if ( $verbose ) { + print "Issue id: " . $auto_renew->issue_id . " for borrower: " . $auto_renew->borrowernumber . " and item: " . $auto_renew->itemnumber; + $commit ? print " will not be renewed " : print " would not be renewed "; + print "($error)\n"; + } if ( not $auto_renew->auto_renew_error or $error ne $auto_renew->auto_renew_error ) { - $auto_renew->auto_renew_error($error)->store; + $auto_renew->auto_renew_error($error)->store if $commit; push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew if $error ne 'auto_too_soon'; # Do not notify if it's too soon } @@ -124,7 +144,7 @@ if ( $send_notices ) { message_transport_type => 'email', from_address => $admin_email_address, } - ); + ) if $commit; } } } -- 2.39.5