Bugzilla – Attachment 99574 Details for
Bug 24724
Add plugin hook for new SQL report export formats
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24724: Add plugin hook for new SQL report export formats
0001-Bug-24724-Add-plugin-hook-for-new-SQL-report-export-.patch (text/plain), 6.23 KB, created by
paxed
on 2020-02-25 11:20:28 UTC
(
hide
)
Description:
Bug 24724: Add plugin hook for new SQL report export formats
Filename:
MIME Type:
Creator:
paxed
Created:
2020-02-25 11:20:28 UTC
Size:
6.23 KB
patch
obsolete
>From 0e019fd90408634c49450b0bbbc84668c96175df Mon Sep 17 00:00:00 2001 >From: Pasi Kallinen <pasi.kallinen@koha-suomi.fi> >Date: Tue, 25 Feb 2020 12:40:27 +0200 >Subject: [PATCH] Bug 24724: Add plugin hook for new SQL report export formats > >This adds plugin hooks for adding new export formats for >SQL reports. > >The plugin should implement two new methods: >- sql_report_get_export_formats > Takes no parameters. > Should return an array ref of hashes, with the following keys: > shortname => 'dump', > name => 'Name of this format', > type => 'text/plain' >- sql_report_process_data > Takes 3 parameters: format, headers, and data. > - format is string the shortname from one of the hashes in > sql_report_get_export_formats. > - headers is array ref of strings, column names of the data. > - data is the data as returned by perl DBI fetchall_arrayref() > >Test plan: >1) Enable plugins, and install the example plugin for the bug >2) Create a new SQL report, eg. "SELECT * FROM BORROWERS LIMIT 30" >3) Run the report - you should see two new entries in the "Download" > button: "Perl data dump (.dump)" and "HTML table (.htm)" >4) Download the new formats, and inspect the file contents that > they look correct >5) Test the other entries in the download-button and that they work > >Signed-off-by: Pasi Kallinen <pasi.kallinen@koha-suomi.fi> >--- > .../prog/en/includes/reports-toolbar.inc | 3 ++ > reports/guided_reports.pl | 40 +++++++++++++++++++++- > 2 files changed, 42 insertions(+), 1 deletion(-) > >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 fd7ce29ce9..716fcc06b6 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/reports-toolbar.inc >@@ -97,6 +97,9 @@ > <li><a id="csv" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&format=csv&report_id=[% id | html %]&reportname=[% name |uri %][% PROCESS params %]">[% PROCESS 'delimiter_text.inc' %]</a></li> > <li><a id="tab" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&format=tab&report_id=[% id | html %]&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 | html %]&reportname=[% name |uri %][% PROCESS params %]">Open Document Spreadsheet</a></li> >+ [% FOREACH pluginexport IN pluginexports %] >+ <li><a id="[% pluginexport.shortname | html %]" href="/cgi-bin/koha/reports/guided_reports.pl?reports=1&phase=Export&format=[% pluginexport.shortname | uri %]&plugin=[% pluginexport.pluginclass | uri %]&report_id=[% id | html %]&reportname=[% name |uri %][% PROCESS params %]">[% pluginexport.name | html %] (.[% pluginexport.shortname | html %])</a></li> >+ [% END %] > [% IF (results.json) %] > <li><a id="download-chart" href="#">Chart (.svg)</a></li> > [% END %] >diff --git a/reports/guided_reports.pl b/reports/guided_reports.pl >index fa2817f1c7..6cdb9f89e4 100755 >--- a/reports/guided_reports.pl >+++ b/reports/guided_reports.pl >@@ -91,6 +91,20 @@ elsif ($session and not $input->param('clear_filters')) { > $filter = $session->param('report_filter'); > } > >+if (($phase eq 'Run this report' || $phase eq 'Export') && >+ C4::Context->preference('UseKohaPlugins') && C4::Context->config('enable_plugins')) { >+ my @plugins = Koha::Plugins->new()->GetPlugins({ method => 'sql_report_get_export_formats' }); >+ my @exportformats; >+ foreach my $plugin (@plugins) { >+ my @formats = @{ $plugin->sql_report_get_export_formats() }; >+ foreach my $format (@formats) { >+ $format->{'pluginclass'} = $plugin->{'class'}; >+ push(@exportformats, $format); >+ } >+ } >+ $template->param( 'pluginexports' => \@exportformats ); >+} >+ > my $op = $input->param('op') || q||; > > my @errors = (); >@@ -891,12 +905,36 @@ elsif ($phase eq 'Export'){ > my $format = $input->param('format'); > my $reportname = $input->param('reportname'); > my $reportfilename = $reportname ? "$reportname-reportresults.$format" : "reportresults.$format" ; >+ my $pluginclass = $input->param('plugin') || ''; > > ($sql, undef) = get_prepped_report( $sql, \@param_names, \@sql_params ); > my ($sth, $q_errors) = execute_query($sql); > unless ($q_errors and @$q_errors) { > my ( $type, $content ); >- if ($format eq 'tab') { >+ if ($pluginclass =~ /Koha::Plugin::/ && C4::Context->preference('UseKohaPlugins') && C4::Context->config('enable_plugins')) { >+ my $pluginexported = 0; >+ my @plugins = Koha::Plugins->new()->GetPlugins({ method => 'sql_report_get_export_formats', class => $pluginclass }); >+ foreach my $plugin (@plugins) { >+ my @exportformats = @{ $plugin->sql_report_get_export_formats() }; >+ foreach my $exportformat (@exportformats) { >+ next if ($exportformat->{'shortname'} ne $format); >+ my @headers = header_cell_values($sth); >+ my $sql_rows = $sth->fetchall_arrayref(); >+ my ($plugcontent, $error) = $plugin->sql_report_process_data($format, \@headers, $sql_rows); >+ if ($error) { >+ push(@$q_errors, { pluginerr => $error }); >+ } else { >+ $type = $exportformat->{'type'}; >+ $content = $plugcontent; >+ $pluginexported = 1; >+ } >+ } >+ } >+ if (!$pluginexported) { >+ # Should not happen unless you edit url params manually, or plugin is buggy >+ push(@$q_errors, { pluginerr => 'Unknown plugin or plugin output format' }); >+ } >+ } elsif ($format eq 'tab') { > $type = 'application/octet-stream'; > $content .= join("\t", header_cell_values($sth)) . "\n"; > $content = Encode::decode('UTF-8', $content); >-- >2.11.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 24724
: 99574 |
99575