Bugzilla – Attachment 70245 Details for
Bug 18497
Downloading a report passes the constructed SQL as a parameter
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18947 - Use report id to retrieve saved SQL instead of passing param
Bug-18947---Use-report-id-to-retrieve-saved-SQL-in.patch (text/plain), 5.97 KB, created by
Nick Clemens (kidclamp)
on 2018-01-03 13:18:01 UTC
(
hide
)
Description:
Bug 18947 - Use report id to retrieve saved SQL instead of passing param
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2018-01-03 13:18:01 UTC
Size:
5.97 KB
patch
obsolete
>From 060790e2ea937fe56a00483b18f20803188b8eb2 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Wed, 3 Jan 2018 13:13:40 +0000 >Subject: [PATCH] Bug 18947 - Use report id to retrieve saved SQL instead of > passing param > >This patch takes some of the code when executing report and moves it to >a sub to be reused when downloading > >To test: >1 - Run some very long report (see comment #1) >2 - Try to download, erk! >3 - Apply patch >4 - Run report, results hould not have changed >5 - Try to download, success! >6 - Ensure reports work as before > >https://bugs.koha-community.org/show_bug.cgi?id=18497 >--- > .../prog/en/includes/reports-toolbar.inc | 10 +++-- > reports/guided_reports.pl | 44 +++++++++++++--------- > 2 files changed, 33 insertions(+), 21 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc >index d7fa79d..00edf94 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc >@@ -47,12 +47,16 @@ > [% END %] > > [% IF ( execute ) %] >+ [% BLOCK params %] >+ [% FOREACH param IN sql_params %]&sql_params=[% param %][% END %] >+ [% END %] >+ > <div class="btn-group"> > <button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" id="format"><i class="fa fa-upload"></i> Download <span class="caret"></span></button> > <ul class="dropdown-menu"> >- <li><a id="csv" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&format=csv&sql=[% sql |uri %]&reportname=[% name |uri %]">Comma separated text</a></li> >- <li><a id="tab" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&format=tab&sql=[% sql |uri %]&reportname=[% name |uri %]">Tab separated text</a></li> >- <li><a id="ods" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&format=ods&sql=[% sql |uri %]&reportname=[% name |uri %]">Open Document Spreadsheet</a></li> >+ <li><a id="csv" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&format=csv&report_id=[% id %]&reportname=[% name |uri %][% PROCESS params %]">Comma separated text</a></li> >+ <li><a id="tab" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&format=tab&report_id=[% id %]&reportname=[% name |uri %][% PROCESS params %]">Tab separated text</a></li> >+ <li><a id="ods" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&format=ods&report_id=[% id %]&reportname=[% name |uri %][% PROCESS params %]">Open Document Spreadsheet</a></li> > </ul> > </div> > <div class="btn-group"> >diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl >index 106ddb5..3126988 100755 >--- a/reports/guided_reports.pl >+++ b/reports/guided_reports.pl >@@ -785,21 +785,7 @@ elsif ($phase eq 'Run this report'){ > 'reports' => $report_id, > ); > } else { >- # OK, we have parameters, or there are none, we run the report >- # if there were parameters, replace before running >- # split on ??. Each odd (2,4,6,...) entry should be a parameter to fill >- my @split = split /<<|>>/,$sql; >- my @tmpl_parameters; >- for(my $i=0;$i<$#split/2;$i++) { >- my $quoted = $sql_params[$i]; >- # if there are special regexp chars, we must \ them >- $split[$i*2+1] =~ s/(\||\?|\.|\*|\(|\)|\%)/\\$1/g; >- if ($split[$i*2+1] =~ /\|\s*date\s*$/) { >- $quoted = output_pref({ dt => dt_from_string($quoted), dateformat => 'iso', dateonly => 1 }) if $quoted; >- } >- $quoted = C4::Context->dbh->quote($quoted); >- $sql =~ s/<<$split[$i*2+1]>>/$quoted/; >- } >+ my $sql = get_prepped_report( $sql, @sql_params ); > my ( $sth, $errors ) = execute_query( $sql, $offset, $limit, undef, $report_id ); > my $total = nb_rows($sql) || 0; > unless ($sth) { >@@ -841,10 +827,15 @@ elsif ($phase eq 'Run this report'){ > elsif ($phase eq 'Export'){ > > # export results to tab separated text or CSV >- my $sql = $input->param('sql'); # FIXME: use sql from saved report ID#, not new user-supplied SQL! >- my $format = $input->param('format'); >- my $reportname = $input->param('reportname'); >+ my $report_id = $input->param('report_id'); >+ my $report = get_saved_report($report_id); >+ my $sql = $report->{savedsql}; >+ my @sql_params = $input->multi_param('sql_params'); >+ my $format = $input->param('format'); >+ my $reportname = $input->param('reportname'); > my $reportfilename = $reportname ? "$reportname-reportresults.$format" : "reportresults.$format" ; >+ >+ $sql = get_prepped_report( $sql, @sql_params ); > my ($sth, $q_errors) = execute_query($sql); > unless ($q_errors and @$q_errors) { > my ( $type, $content ); >@@ -1053,3 +1044,20 @@ sub create_non_existing_group_and_subgroup { > } > } > } >+ >+# pass $sth and sql_params, get back an executable query >+sub get_prepped_report { >+ my ($sql, @sql_params ) = @_; >+ my @split = split /<<|>>/,$sql; >+ for(my $i=0;$i<$#split/2;$i++) { >+ my $quoted = $sql_params[$i]; >+ # if there are special regexp chars, we must \ them >+ $split[$i*2+1] =~ s/(\||\?|\.|\*|\(|\)|\%)/\\$1/g; >+ if ($split[$i*2+1] =~ /\|\s*date\s*$/) { >+ $quoted = output_pref({ dt => dt_from_string($quoted), dateformat => 'iso', dateonly => 1 }) if $quoted; >+ } >+ $quoted = C4::Context->dbh->quote($quoted); >+ $sql =~ s/<<$split[$i*2+1]>>/$quoted/; >+ } >+ return $sql; >+} >-- >2.1.4
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 18497
:
65338
|
65339
|
70245
|
70637
|
70639
|
71060
|
71061
|
71080
|
71081