Bug 2389: Add --test switch to overdue_notices.pl
authorTomas Cohen Arazi <tomascohen@theke.io>
Fri, 15 Jul 2016 13:18:13 +0000 (10:18 -0300)
committerKyle M Hall <kyle@bywatersolutions.com>
Sat, 24 Sep 2016 16:27:10 +0000 (16:27 +0000)
This patch adds the --test option switch to the overdue_notices.pl script
so it can be ran without doing any actual action.

To test:
- Have a patron with overdue items (simulate a checkout for a past date. Note it implies
  that the circ rules are defined so the patron is overdue)
- Run:
  $ sudo koha-shell kohadev
  koha-dev$ misc/cronjobs/overdue_notices.pl --test
=> SUCCESS: The script is ran but the patron isn't debarred and no notice messages are queued.

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: Barton Chittenden <barton@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
misc/cronjobs/overdue_notices.pl

index 050882d..0b9d623 100755 (executable)
@@ -281,6 +281,7 @@ my $man     = 0;
 my $verbose = 0;
 my $nomail  = 0;
 my $MAX     = 90;
+my $test_mode = 0;
 my @branchcodes; # Branch(es) passed as parameter
 my @emails_to_use;    # Emails to use for messaging
 my @emails;           # Emails given in command-line parameters
@@ -307,6 +308,7 @@ GetOptions(
     'itemscontent=s' => \$itemscontent,
     'list-all'       => \$listall,
     't|triggered'    => \$triggered,
+    'test'           => \$test_mode,
     'date=s'         => \$date_input,
     'borcat=s'       => \@myborcat,
     'borcatout=s'    => \@myborcatout,
@@ -315,7 +317,7 @@ GetOptions(
 pod2usage(1) if $help;
 pod2usage( -verbose => 2 ) if $man;
 
-cronlogaction();
+cronlogaction() unless $test_mode;
 
 if ( defined $csvfilename && $csvfilename =~ /^-/ ) {
     warn qq(using "$csvfilename" as filename, that seems odd);
@@ -600,7 +602,7 @@ END_SQL
                             type           => 'OVERDUES',
                             comment => "OVERDUES_PROCESS " .  output_pref( dt_from_string() ),
                         }
-                    );
+                    ) unless $test_mode;
                     $verbose and warn "debarring $borr\n";
                 }
                 my @params = ($borrowernumber);
@@ -757,7 +759,7 @@ END_SQL
                                     from_address           => $admin_email_address,
                                     to_address             => join(',', @emails_to_use),
                                 }
-                            );
+                            ) unless $test_mode;
                             # A print notice should be sent only once per overdue level.
                             # Without this check, a print could be sent twice or more if the library checks sms and email and print and the patron has no email or sms number.
                             $print_sent = 1 if $effective_mtt eq 'print';