LP#1198465 Make generate_fines() chattiness optional
authorDan Wells <dbw2@calvin.edu>
Fri, 5 Dec 2014 17:49:41 +0000 (12:49 -0500)
committerDan Wells <dbw2@calvin.edu>
Mon, 8 Dec 2014 14:38:40 +0000 (09:38 -0500)
The old storage generate_fines() was really chatty with it's client. We
generally won't want that, so make it optional.

Also, remove one response which I added earlier while debugging.

Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm

index caf2da1..3fd8aad 100644 (file)
@@ -393,10 +393,13 @@ sub seconds_to_interval_hash {
 }
 
 sub generate_fines {
-    my ($class, $conn, $args) = @_;
+    my ($class, $args) = @_;
     my $circs = $args->{circs};
       return unless $circs and @$circs;
     my $e = $args->{editor};
+    # if a client connection is passed in, this will be chatty like
+    # the old storage version
+    my $conn = $args->{conn};
 
     my $commit = 0;
     unless ($e) {
@@ -450,7 +453,7 @@ sub generate_fines {
             $fine_interval = interval_to_seconds( $fine_interval );
     
             if ( $fine_interval == 0 || int($c->$recurring_fine_method * 100) == 0 || int($c->max_fine * 100) == 0 ) {
-                $conn->respond( "Fine Generator skipping circ due to 0 fine interval, 0 fine rate, or 0 max fine.\n" );
+                $conn->respond( "Fine Generator skipping circ due to 0 fine interval, 0 fine rate, or 0 max fine.\n" ) if $conn;
                 $logger->info( "Fine Generator skipping circ " . $c->id . " due to 0 fine interval, 0 fine rate, or 0 max fine." );
                 return;
             }
@@ -469,7 +472,7 @@ sub generate_fines {
                 "ARG! Overdue $ctype ".$c->id.
                 " for item ".$c->$target_copy_method.
                 " (user ".$c->usr.").\n".
-                "\tItem was due on or before: ".localtime($due)."\n");
+                "\tItem was due on or before: ".localtime($due)."\n") if $conn;
     
             my @fines = @{$e->search_money_billing(
                 { xact => $c->id,
@@ -485,7 +488,7 @@ sub generate_fines {
     
             my $last_fine;
             if ($fine) {
-                $conn->respond( "Last billing time: ".$fine->billing_ts." (clensed format: ".cleanse_ISO8601( $fine->billing_ts ).")");
+                $conn->respond( "Last billing time: ".$fine->billing_ts." (clensed format: ".cleanse_ISO8601( $fine->billing_ts ).")") if $conn;
                 $last_fine = $parser->parse_datetime( cleanse_ISO8601( $fine->billing_ts ) )->epoch;
             } else {
                 $logger->info( "Potential first billing for circ ".$c->id );
@@ -502,12 +505,12 @@ sub generate_fines {
                  && $grace_period                           # and we have a grace period
                  && $now < $due + $grace_period             # and some date math says were are within the grace period
             ) {
-                $conn->respond( "Still inside grace period of: ". seconds_to_interval( $grace_period )."\n" );
+                $conn->respond( "Still inside grace period of: ". seconds_to_interval( $grace_period )."\n" ) if $conn;
                 $logger->info( "Circ ".$c->id." is still inside grace period of: $grace_period [". seconds_to_interval( $grace_period ).']' );
                 return;
             }
 
-            $conn->respond( "\t$pending_fine_count pending fine(s)\n" );
+            $conn->respond( "\t$pending_fine_count pending fine(s)\n" ) if $conn;
             return unless ($pending_fine_count);
 
             my $recurring_fine = int($c->$recurring_fine_method * 100);
@@ -533,7 +536,7 @@ sub generate_fines {
                     $conn->respond(
                         "\tMaximum fine level of ".$c->max_fine.
                         " reached for this $ctype.\n".
-                        "\tNo more fines will be generated.\n" );
+                        "\tNo more fines will be generated.\n" ) if $conn;
                     last;
                 }
                 
@@ -571,7 +574,6 @@ sub generate_fines {
                     $this_billing_amount = ($max_fine - $current_fine_total);
                 }
                 $current_fine_total += $this_billing_amount;
-                $conn->respond("CFT:" . $current_fine_total);
                 $latest_amount += $this_billing_amount;
                 $latest_billing_ts = $timestamptz;
 
@@ -587,7 +589,7 @@ sub generate_fines {
             }
 
             $conn->respond( "\t\tAdding fines totaling $latest_amount for overdue up to $latest_billing_ts\n" )
-                if ($latest_billing_ts and $latest_amount);
+                if ($conn and $latest_billing_ts and $latest_amount);
 
 #            $self->method_lookup('open-ils.storage.transaction.commit')->run;
 
@@ -599,7 +601,7 @@ sub generate_fines {
 
         if ($@) {
             my $e = $@;
-            $conn->respond( "Error processing overdue $ctype [".$c->id."]:\n\n$e\n" );
+            $conn->respond( "Error processing overdue $ctype [".$c->id."]:\n\n$e\n" ) if $conn;
             $logger->error("Error processing overdue $ctype [".$c->id."]:\n$e\n");
 #            $self->method_lookup('open-ils.storage.transaction.rollback')->run;
             last if ($e =~ /IS NOT CONNECTED TO THE NETWORK/o);
index 861256f..fb53a41 100644 (file)
@@ -992,7 +992,7 @@ sub generate_fines {
         $circs = [map { $_->to_fieldmapper } overdue_circs()];
     }
 
-    return OpenILS::Application::Circ::CircCommon->generate_fines($client, {circs => $circs})
+    return OpenILS::Application::Circ::CircCommon->generate_fines({circs => $circs, conn => $client})
 }
 __PACKAGE__->register_method(
     api_name        => 'open-ils.storage.action.circulation.overdue.generate_fines',