Bug 21620: Prevent stockrotation cronjob failures
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Fri, 19 Oct 2018 13:37:26 +0000 (14:37 +0100)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 2 Nov 2018 10:33:00 +0000 (10:33 +0000)
Superflous use of sprintf combined with rebasing issue left the
stockrotation cronjob such that a 'No action taken' email report would
catastrophically fail with the error:

Redundant argument in sprintf at ./stockrotation.pl line 316

This patch both resolves the error and cleans up some additional
unrequired sprintf usage.

Test Plan
1) Create a rotation plan
2) Add some items to the rotation plan
3) Run the cronjob using `stockrotation.pl --report=email --send-email
--execute`
4) Note the lack of errors

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

misc/cronjobs/stockrotation.pl

index a6cd0c1..083c147 100755 (executable)
@@ -216,9 +216,8 @@ sub report_full {
     my $body   = "";
 
     # Summary
-    $header .= sprintf "
-STOCKROTATION REPORT
---------------------\n";
+    $header .= "STOCKROTATION REPORT\n";
+    $header .= "--------------------\n";
     $body .= sprintf "
   Total number of rotas:         %5u
     Inactive rotas:              %5u
@@ -237,25 +236,25 @@ STOCKROTATION REPORT
       $data->{advanceable}, $data->{indemand};
 
     if ( @{ $data->{rotas} } ) {    # Per Rota details
-        $body .= sprintf "ROTAS DETAIL\n------------\n\n";
+        $body .= "ROTAS DETAIL\n";
+        $body .= "------------\n\n";
         foreach my $rota ( @{ $data->{rotas} } ) {
             $body .= sprintf "Details for %s [%s]:\n",
               $rota->{name}, $rota->{id};
-            $body .= sprintf "\n  Items:";    # Rota item details
+            $body .= "\n  Items:";    # Rota item details
             if ( @{ $rota->{items} } ) {
                 $body .=
                   join( "", map { _print_item($_) } @{ $rota->{items} } );
             }
             else {
-                $body .=
-                  sprintf "\n    No items to be processed for this rota.\n";
+                $body .= "\n    No items to be processed for this rota.\n";
             }
-            $body .= sprintf "\n  Log:";      # Rota log details
+            $body .= "\n  Log:";      # Rota log details
             if ( @{ $rota->{log} } ) {
                 $body .= join( "", map { _print_item($_) } @{ $rota->{log} } );
             }
             else {
-                $body .= sprintf "\n    No items in log for this rota.\n\n";
+                $body .= "\n    No items in log for this rota.\n\n";
             }
         }
     }
@@ -298,9 +297,8 @@ sub report_email {
     my $branched = $data->{branched};
     my $flag     = 0;
 
-    $header .= sprintf "
-BRANCH-BASED STOCKROTATION REPORT
----------------------------------\n";
+    $header .= "BRANCH-BASED STOCKROTATION REPORT\n";
+    $header .= "---------------------------------\n";
     push @{$out}, $header;
 
     if ($branch) {    # Branch limited report
@@ -314,8 +312,7 @@ BRANCH-BASED STOCKROTATION REPORT
     }
     else {
         push @{$out}, {
-            body => sprintf "
-No actionable items at any libraries.\n\n",    # The body of the report
+            body => "No actionable items at any libraries.\n\n",    # The body of the report
             no_branch_email => 1,    # We don't expect branch email in report
         };
     }