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>
Tue, 17 Feb 2015 21:04:22 +0000 (16:04 -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 2c2d4d3..9be2fd7 100644 (file)
@@ -354,10 +354,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) {
@@ -428,7 +431,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;
             }
@@ -447,7 +450,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,
@@ -463,7 +466,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 );
@@ -480,12 +483,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);
@@ -511,7 +514,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;
                 }
                 
@@ -564,7 +567,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;
 
@@ -576,7 +579,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 2f9b9c5..8d272a0 100644 (file)
@@ -1015,7 +1015,7 @@ sub generate_fines {
         $circs = [map { $_->to_fieldmapper } overdue_circs(undef, 1, 1, 1)];
     }
 
-    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',