Bug 24724 - Add plugin hook for new SQL report export formats
Summary: Add plugin hook for new SQL report export formats
Status: In Discussion
Alias: None
Product: Koha
Classification: Unclassified
Component: Plugin architecture (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: paxed
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-25 11:13 UTC by paxed
Modified: 2020-09-29 15:15 UTC (History)
1 user (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 24724: Add plugin hook for new SQL report export formats (6.23 KB, patch)
2020-02-25 11:20 UTC, paxed
Details | Diff | Splinter Review
Plugin to test Bug 24724 (1.59 KB, application/zip)
2020-02-25 11:21 UTC, paxed
Details

Note You need to log in before you can comment on or make changes to this bug.
Description paxed 2020-02-25 11:13:35 UTC
There should be a plugin hook for adding new SQL report export formats.
Comment 1 paxed 2020-02-25 11:20:28 UTC
Created attachment 99574 [details] [review]
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
Comment 2 paxed 2020-02-25 11:21:05 UTC
Created attachment 99575 [details]
Plugin to test Bug 24724
Comment 3 Fridolin Somers 2020-03-21 12:09:20 UTC
I propose you to depend on Bug 20415 that removes UseKohaPlugins system preference
Comment 4 Fridolin Somers 2020-09-29 12:15:01 UTC
Ah really nice hook.

I think it could be useful for many other exports (checkouts table, ...).

Use of those plugins will only be implemented only for sql reports, but can be implemented somewhere else in a second time.

So I propose you some changes :

1)
Only one format per plugin. 2 formats = create 2 plugins ;)
Will make code more clear I bet.

2)
Change methods :
    sub sql_report_get_export_format
    sub sql_report_process_data
to :
    export_format
    process_export

3)
Better add a method to Koha/Template/Plugin/KohaPlugins.pm to fetch the plugins you need.

PS : you need to remove call to UseKohaPlugins system preference

Let me know if you need help.

Best regards,
Comment 5 Katrin Fischer 2020-09-29 12:33:05 UTC

Maybe we should keep sql in the hook name - I could imagine other spots it could be different data formats to export/convert?
Comment 6 Fridolin Somers 2020-09-29 15:15:26 UTC
(In reply to Katrin Fischer from comment #5)
> 
> Maybe we should keep sql in the hook name - I could imagine other spots it
> could be different data formats to export/convert?

Ah yes I see, method should indicate where the plugin impacts.

I suggest we keep "report" instead of "sql" :
report_export_format
report_process_export

So a another place, ie checkouts, with exports will add hooks :
checkouts_export_format
checkouts_process_export

Since a plugin can handle several hooks its fine :D