Bugzilla – Attachment 158102 Details for
Bug 35171
runreport.pl cronjob should optionally send an email when the report has no results
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35171: Add send_empty option to runreport
Bug-35171-Add-sendempty-option-to-runreport.patch (text/plain), 3.78 KB, created by
Victor Grousset/tuxayo
on 2023-10-30 20:00:21 UTC
(
hide
)
Description:
Bug 35171: Add send_empty option to runreport
Filename:
MIME Type:
Creator:
Victor Grousset/tuxayo
Created:
2023-10-30 20:00:21 UTC
Size:
3.78 KB
patch
obsolete
>From 65cced778aa74765878afcb6f250a2997a37a306 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Thu, 26 Oct 2023 18:03:40 +0000 >Subject: [PATCH] Bug 35171: Add send_empty option to runreport > >This patch adds a new 'send_empty' option to runreport.pl > >To test: >1 - Create a report in Koha that will not return any results: > SELECT barcode FROM items WHERE 1=2 >2 - perl misc/cronjobs/runreport.pl 1 >3 - Output is: NO OUTPUT: 0 results from execute_query >4 - perl misc/cronjobs/runreport.pl 1 --send_empty >5 - Output is: no results were returned for the report >6 - perl misc/cronjobs/runreport.pl 1 --send_empty --email >7 - It will die on an email error unless you have SMTP configured - this si good, it means we sent an email >8 - Bonus points: Test on a system that can correctly send emails, confirm it works :-) > >Signed-off-by: David Nind <david@davidnind.com> >Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> >--- > misc/cronjobs/runreport.pl | 37 +++++++++++++++++++++---------------- > 1 file changed, 21 insertions(+), 16 deletions(-) > >diff --git a/misc/cronjobs/runreport.pl b/misc/cronjobs/runreport.pl >index debcf5a024..656ce34d07 100755 >--- a/misc/cronjobs/runreport.pl >+++ b/misc/cronjobs/runreport.pl >@@ -54,6 +54,7 @@ runreport.pl [ -h | -m ] [ -v ] reportID [ reportID ... ] > --format=s selects format. Choice of text, html, csv or tsv > > -e --email whether to use e-mail (implied by --to or --from) >+ --send_empty whether to send an email when there are no results from the specified report > -a --attachment additionally attach the report as a file. cannot be used with html format > --username username to pass to the SMTP server for authentication > --password password to pass to the SMTP server for authentication >@@ -173,20 +174,21 @@ binmode STDOUT, ":encoding(UTF-8)"; > # These variables can be set by command line options, > # initially set to default values. > >-my $help = 0; >-my $man = 0; >-my $verbose = 0; >-my $send_email = 0; >-my $attachment = 0; >-my $format = "text"; >-my $to = ""; >-my $from = ""; >-my $subject = ""; >-my @params = (); >-my $separator = ','; >-my $quote = '"'; >+my $help = 0; >+my $man = 0; >+my $verbose = 0; >+my $send_email = 0; >+my $send_empty = 0; >+my $attachment = 0; >+my $format = "text"; >+my $to = ""; >+my $from = ""; >+my $subject = ""; >+my @params = (); >+my $separator = ','; >+my $quote = '"'; > my $store_results = 0; >-my $csv_header = 0; >+my $csv_header = 0; > my $csv_separator = ""; > > my $username = undef; >@@ -206,6 +208,7 @@ GetOptions( > 'subject=s' => \$subject, > 'param=s' => \@params, > 'email' => \$send_email, >+ 'send_empty' => \$send_empty, > 'a|attachment' => \$attachment, > 'username:s' => \$username, > 'password:s' => \$password, >@@ -288,7 +291,7 @@ foreach my $report_id (@ARGV) { > } > ); > my $count = scalar($sth->rows); >- unless ($count) { >+ unless ($count || $send_empty ) { > print "NO OUTPUT: 0 results from execute_query\n"; > next; > } >@@ -296,7 +299,9 @@ foreach my $report_id (@ARGV) { > > my $message; > my @rows_to_store; >- if ($format eq 'html') { >+ if( !$count ){ >+ $message = "No results were returned for the report\n"; >+ } elsif ($format eq 'html') { > my $cgi = CGI->new(); > my @rows; > while (my $line = $sth->fetchrow_arrayref) { >@@ -327,7 +332,7 @@ foreach my $report_id (@ARGV) { > } > $message = Encode::decode_utf8($message); > } >- if ( $store_results ) { >+ if ( $store_results && $count ) { > my $json = to_json( \@rows_to_store ); > C4::Reports::Guided::store_results( $report_id, $json ); > } >-- >2.42.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35171
:
157944
|
158016
| 158102 |
158103