From b55ebb4d5dbb9cbcaead5bcbbace0bf4e5a41f93 Mon Sep 17 00:00:00 2001
From: Fridolin Somers <fridolin.somers@biblibre.com>
Date: Wed, 22 Feb 2023 20:40:14 -1000
Subject: [PATCH] Bug 33050: More args for misc/cronjobs/runreport.pl

Add to script misc/cronjobs/runreport.pl args for CSV :
  * separator character
  * quote character
  * no quote (by default double quote)

See perl doc https://metacpan.org/pod/Text::CSV#new

Test plan :
Play with each arg and compare results of runreport.pl
---
 misc/cronjobs/runreport.pl | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/misc/cronjobs/runreport.pl b/misc/cronjobs/runreport.pl
index 8b3c12b3b0..36b42d7da0 100755
--- a/misc/cronjobs/runreport.pl
+++ b/misc/cronjobs/runreport.pl
@@ -63,6 +63,9 @@ runreport.pl [ -h | -m ] [ -v ] reportID [ reportID ... ]
    --subject=s     subject for the e-mail
    --param=s      parameters for the report
    --store-results store the result of the report
+   --separator     separator character for CSV
+   --quote         quote character in CSV
+   --no-quote      no quote character in CSV
    --csv-header    add column names as first line of csv output
 
 
@@ -129,6 +132,18 @@ Store the result of the report into the saved_reports DB table.
 
 To access the results, go on Reports > Guided reports > Saved report.
 
+=item B<--separator>
+
+Separator character for CSV, by default comma.
+
+=item B<--quote>
+
+Quote char in CSV, by default double quote.
+
+=item B<--no-quote>
+
+No quote char in CSV.
+
 =back
 
 =head1 DESCRIPTION
@@ -181,6 +196,7 @@ my $subject = "";
 my @params = ();
 my $separator = ',';
 my $quote = '"';
+my $no_quote = 0;
 my $store_results = 0;
 my $csv_header = 0;
 
@@ -205,6 +221,9 @@ GetOptions(
     'password:s'        => \$password,
     'method:s'          => \$method,
     'store-results'     => \$store_results,
+    'separator=s'       => \$separator,
+    'quote=s'           => \$quote,
+    'no-quote'          => \$no_quote,
     'csv-header'        => \$csv_header,
 
 ) or pod2usage(2);
@@ -298,6 +317,7 @@ foreach my $report_id (@ARGV) {
             quote_char  => $quote,
             sep_char    => $separator,
             });
+        $csv->quote_char(undef) if $no_quote;
 
         if ( $csv_header ) {
             my @fields = map { decode( 'utf8', $_ ) } @{ $sth->{NAME} };
-- 
2.39.0