From c636d84e7e9808a0c40ab3d94642d52c895d9fd4 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Tue, 7 Jan 2014 14:39:46 -0500 Subject: [PATCH] Bug 11491 - Missing header fields in JSON data Added a header parameter, which when non-empty will add the header fields of the query in question as the first element of the JSON array. Added header ability to staff svc/report as well. Moved code around to make diffs between svc/report and opac/svc/report smaller. TEST PLAN --------- 1) Log into staff client 2) Reports 3) Used save reports 4) Click the Action button on any report 5) Click Edit 6) Make the report public 7) Update the SQL 8) Note the ID number of the report 9) In a new tab https://.../cgi-bin/koha/svc/report?id=## 10) The returned JSON should not have a header. 11) Go to https://.../cgi-bin/koha/svc/report?id=##&header=1 12) The returned JSON should have a header. 13) ~/qa-test-tools/koha-qa.pl -v 2 -c 2 NOTE: There are two patches, but you could just test 1. --- opac/svc/report | 6 +++++- svc/report | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/opac/svc/report b/opac/svc/report index 38cbd42..31a653a 100755 --- a/opac/svc/report +++ b/opac/svc/report @@ -30,11 +30,11 @@ use Koha::Cache; my $query = CGI->new(); my $report_id = $query->param('id'); my $report_name = $query->param('name'); +my $report_header = $query->param('header'); my $report_rec = get_saved_report( $report_name ? { 'name' => $report_name } : { 'id' => $report_id } ); die "Sorry this report is not public\n" unless $report_rec->{public}; - my $cache_active = Koha::Cache->is_cache_active; my ($cache_key, $cache, $json_text); if ($cache_active) { @@ -48,7 +48,11 @@ unless ($json_text) { my $limit = C4::Context->preference("SvcMaxReportRows") || 10; my ( $sth, $errors ) = execute_query( $report_rec->{savedsql}, $offset, $limit ); if ($sth) { + my $header = $sth->{NAME}; my $lines = $sth->fetchall_arrayref; + if ($report_header) { + unshift @{$lines}, [ @{$header} ]; + } $json_text = to_json($lines); if ($cache_active) { diff --git a/svc/report b/svc/report index 654ef15..8fc973a 100755 --- a/svc/report +++ b/svc/report @@ -32,7 +32,9 @@ use Koha::Cache; my $query = CGI->new(); my $report_id = $query->param('id'); my $report_name = $query->param('name'); +my $report_header = $query->param('header'); +my $report_rec = get_saved_report( $report_name ? { 'name' => $report_name } : { 'id' => $report_id } ); my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { template_name => "intranet-main.tmpl", @@ -52,12 +54,15 @@ if ($cache_active) { } unless ($json_text) { - my $report_rec = get_saved_report($report_name ? { 'name' => $report_name } : { 'id' => $report_id }); my $offset = 0; my $limit = C4::Context->preference("SvcMaxReportRows") || 10; my ( $sth, $errors ) = execute_query( $report_rec->{savedsql}, $offset, $limit ); if ($sth) { + my $header = $sth->{NAME}; my $lines = $sth->fetchall_arrayref; + if ($report_header) { + unshift @{$lines}, [ @{$header} ]; + } $json_text = to_json($lines); if ($cache_active) { -- 1.7.9.5