Bugzilla – Attachment 3487 Details for
Bug 5253
runreport.pl does not work with new options (-to, -from, -email, -format)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Proposed patch
0001-Bug-5253-Add-options-to-runreport.pl.patch (text/plain), 4.76 KB, created by
Ian Walls
on 2011-03-29 01:30:14 UTC
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Ian Walls
Created:
2011-03-29 01:30:14 UTC
Size:
4.76 KB
patch
obsolete
>From 9158fe8402a8e20d96935ffe1f2a6f003c4dedea Mon Sep 17 00:00:00 2001 >From: Jared Camins-Esakov <jcamins@bywatersolutions.com> >Date: Sun, 27 Mar 2011 11:51:35 -0400 >Subject: [PATCH] Bug 5253: Add options to runreport.pl >Content-Type: text/plain; charset="utf-8" > >This makes sending reports via e-mail with runreport.pl work properly. It also >adds a --format option to allow the user to select between text, html, csv, and >tsv. At the moment text is not implemented, and falls back to tsv, but that is >still more readable than the HTML that used to be produced. > >Signed-off-by: Ian Walls <ian.walls@bywatersolutions.com> >--- > misc/cronjobs/runreport.pl | 83 ++++++++++++++++++++++++++++++++++--------- > 1 files changed, 65 insertions(+), 18 deletions(-) > >diff --git a/misc/cronjobs/runreport.pl b/misc/cronjobs/runreport.pl >index d4f5567..6a8cce7 100755 >--- a/misc/cronjobs/runreport.pl >+++ b/misc/cronjobs/runreport.pl >@@ -53,6 +53,14 @@ runreport.pl [ -h | -m ] [ -v ] reportID [ reportID ... ] > -m --man full documentation, same as --help --verbose > -v --verbose verbose output > >+ --format=s selects format. Choice of text, html, csv, or tsv >+ >+ -e --email whether to use e-mail (implied by --to or --from) >+ --to=s e-mail address to send report to >+ --from=s e-mail address to send report from >+ --subject=s subject for the e-mail >+ >+ > Arguments: > reportID report ID Number from saved_sql.id, multiple ID's may be specified > >@@ -72,6 +80,26 @@ Prints the manual page and exits. > > Verbose. Without this flag set, only fatal errors are reported. > >+=item B<-format> >+ >+Current options are text, html, csv, and tsv. At the moment, text and tsv both produce tab-separated tab-separated output. >+ >+=item B<-email> >+ >+Whether to use e-mail (implied by --to or --from). >+ >+=item B<-to> >+ >+E-mail address to send report to. Defaults to KohaAdminEmailAddress. >+ >+=item B<-from> >+ >+E-mail address to send report from. Defaults to KohaAdminEmailAddress. >+ >+=item B<-subject> >+ >+Subject for the e-mail message. Defaults to "Koha Saved Report" >+ > =back > > =head1 DESCRIPTION >@@ -93,17 +121,11 @@ Same as above, but also runs report #17. > > =over > >-=item * >- >-Complete testing for Sendmail related options: --email, --to, and --from. > > =item * > > Allow Saved Results option. > >-=item * >- >-Possible --format option for CSV or tab-delimited output. > > =back > >@@ -120,18 +142,21 @@ my $help = 0; > my $man = 0; > my $verbose = 0; > my $email = 0; >-my $format = ""; >+my $format = "text"; > my $to = ""; > my $from = ""; > my $subject = 'Koha Saved Report'; >+my $separator = ','; >+my $quote = '"'; > > GetOptions( > 'help|?' => \$help, > 'man' => \$man, > 'verbose' => \$verbose, >- 'format' => \$format, >- 'to' => \$to, >- 'from' => \$from, >+ 'format=s' => \$format, >+ 'to=s' => \$to, >+ 'from=s' => \$from, >+ 'subject=s' => \$subject, > 'email' => \$email, > ) or pod2usage(2); > pod2usage( -verbose => 2 ) if ($man); >@@ -140,8 +165,12 @@ pod2usage(1) if $help; > > unless ($format) { > $verbose and print STDERR "No format specified, assuming 'text'\n"; >- $format = ''; >- # $format = 'text'; >+ $format = 'text'; >+} >+ >+if ($format eq 'tsv' || $format eq 'text') { >+ $format = 'csv'; >+ $separator = "\t"; > } > > if ($to or $from or $email) { >@@ -174,13 +203,31 @@ foreach my $report (@ARGV) { > } > $verbose and print "$count results from execute_query\n"; > >- my $cgi = CGI->new(); >- my @rows = (); >- while (my $line = $sth->fetchrow_arrayref) { >- foreach (@$line) { defined($_) or $_ = ''; } # catch undef values, replace w/ '' >- push @rows, $cgi->TR( join('', $cgi->td($line)) ) . "\n"; >+ my $message; >+ if ($format eq 'html') { >+ my $cgi = CGI->new(); >+ my @rows = (); >+ while (my $line = $sth->fetchrow_arrayref) { >+ foreach (@$line) { defined($_) or $_ = ''; } # catch undef values, replace w/ '' >+ push @rows, $cgi->TR( join('', $cgi->td($line)) ) . "\n"; >+ } >+ $message = $cgi->table(join "", @rows); >+ } elsif ($format eq 'csv') { >+ my $csv = Text::CSV_XS->new({ >+ quote_char => $quote, >+ sep_char => $separator, >+ }); >+ while (my $line = $sth->fetchrow_arrayref) { >+ $csv->combine(@$line); >+# foreach (@$line) { >+# defined($_) or $_ = ''; >+# $_ =~ s/$quote/\\$quote/g; >+# $_ = "$quote$_$quote"; >+# } # catch undef values, replace w/ '' >+# $message .= join ($separator, @$line) . "\n"; >+ $message .= $csv->string() . "\n"; >+ } > } >- my $message = $cgi->table(join "", @rows); > > if ($email){ > my %mail = ( >-- >1.5.6.5 >
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 5253
: 3487