[Bug 34335] New: Run Koha plugin method from CLI
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34335 Bug ID: 34335 Summary: Run Koha plugin method from CLI Change sponsored?: --- Product: Koha Version: master Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: Plugin architecture Assignee: koha-bugs@lists.koha-community.org Reporter: dcook@prosentient.com.au QA Contact: testopia@bugs.koha-community.org There are times where it would be nice to run a Koha plugin method from the CLI. This can actually be achieved with very little code thanks to Koha::Plugins::Handler->run(). -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34335 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |dcook@prosentient.com.au |ity.org | -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34335 --- Comment #1 from David Cook <dcook@prosentient.com.au> --- *** Bug 26169 has been marked as a duplicate of this bug. *** -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34335 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34335 --- Comment #2 from David Cook <dcook@prosentient.com.au> --- Created attachment 153746 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=153746&action=edit Bug 34335: Add a script to run Koha plugin methods from the CLI This change adds a script which allows you to run a method from a Koha plugin. Test plan: 0. Apply patch 1. Upload test plugin 2. Run the following: perl misc/run_koha_plugin.pl --class Koha::Plugin::Prosentient::CustomMethodPlugin --method awesome_method 3. Note the following CLI message: This is a custom method that you're seeing on the CLI! at /var/lib/koha/kohadev/plugins/Koha/Plugin/Prosentient/CustomMethodPlugin.pm line 42. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34335 --- Comment #3 from David Cook <dcook@prosentient.com.au> --- It might be nice to be able to handle method parameters as well... maybe I'll have a little look at that... -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34335 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #153746|0 |1 is obsolete| | --- Comment #4 from David Cook <dcook@prosentient.com.au> --- Created attachment 153747 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=153747&action=edit Bug 34335: Add a script to run Koha plugin methods from the CLI This change adds a script which allows you to run a method from a Koha plugin. Test plan: 0. Apply patch 1. Upload test plugin 2. Run the following: perl misc/run_koha_plugin.pl --class Koha::Plugin::Prosentient::CustomMethodPlugin \ --method awesome_method --params '{"msg": "this is awesome"}' 3. Note the following CLI messages: This is a custom method that you're seeing on the CLI! We got a message: this is awesome -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34335 --- Comment #5 from David Cook <dcook@prosentient.com.au> --- Created attachment 153748 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=153748&action=edit test plugin -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34335 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #153747|0 |1 is obsolete| | --- Comment #6 from David Cook <dcook@prosentient.com.au> --- Created attachment 153749 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=153749&action=edit Bug 34335: Add a script to run Koha plugin methods from the CLI This change adds a script which allows you to run a method from a Koha plugin. Test plan: 0. Apply patch 1. Upload test plugin 2. Run the following: perl misc/run_koha_plugin.pl --class Koha::Plugin::Prosentient::CustomMethodPlugin \ --method awesome_method --params '{"msg": "this is awesome"}' 3. Note the following CLI messages: This is a custom method that you're seeing on the CLI! We got a message: this is awesome -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34335 --- Comment #7 from David Cook <dcook@prosentient.com.au> --- Passing quoted values to koha-shell kohadev -c "" doesn't work so well... so might need to have alternate ways of providing the params -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34335 --- Comment #8 from David Cook <dcook@prosentient.com.au> --- (In reply to David Cook from comment #7)
Passing quoted values to koha-shell kohadev -c "" doesn't work so well... so might need to have alternate ways of providing the params
Actually, I figured it out. It just takes a bit of work... -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34335 Paul Derscheid <paul.derscheid@lmscloud.de> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |paul.derscheid@lmscloud.de --- Comment #9 from Paul Derscheid <paul.derscheid@lmscloud.de> --- This is indeed awesome. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34335 Paul Derscheid <paul.derscheid@lmscloud.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Signed Off -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34335 Paul Derscheid <paul.derscheid@lmscloud.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #153749|0 |1 is obsolete| | --- Comment #10 from Paul Derscheid <paul.derscheid@lmscloud.de> --- Created attachment 153760 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=153760&action=edit Bug 34335: Add a script to run Koha plugin methods from the CLI This change adds a script which allows you to run a method from a Koha plugin. Test plan: 0. Apply patch 1. Upload test plugin 2. Run the following: perl misc/run_koha_plugin.pl --class Koha::Plugin::Prosentient::CustomMethodPlugin \ --method awesome_method --params '{"msg": "this is awesome"}' 3. Note the following CLI messages: This is a custom method that you're seeing on the CLI! We got a message: this is awesome Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de> Great stuff! Example works flawlessly. I will now try to break it ;) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34335 Jonathan Druart <jonathan.druart+koha@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jonathan.druart+koha@gmail. | |com --- Comment #11 from Jonathan Druart <jonathan.druart+koha@gmail.com> --- Can you provide some use cases? -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34335 --- Comment #12 from David Cook <dcook@prosentient.com.au> --- (In reply to Jonathan Druart from comment #11)
Can you provide some use cases?
I'm working on a plugin where we schedule a cronjob to execute a plugin method every X minutes. (The "cronjob_nightly" hook isn't frequent/granular enough.) Another use case would be allowing sysadmins to run tools manually on the backend. Could be useful for batch tasks, infrequent tasks, etc. It could be useful for integrations with other systems on the server where you want to avoid the overhead of a HTTP API. (This is something I considered in 2020.) You could use it to configure a plugin in a more automation friendly way. So you could use Ansible to unzip a plugin to a plugin_dir directory, install it with "./misc/devel/install_plugins.pl", and then use this to configure it. -- Anyway, the first use case is the one I'm intentionally targeting. At the moment, I've included this script in the plugin itself. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34335 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=28499 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34335 Marcel de Rooy <m.de.rooy@rijksmuseum.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Signed Off |In Discussion CC| |m.de.rooy@rijksmuseum.nl --- Comment #13 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- Why not just call something like: perl -MKoha::Plugin::RMA::ItemHook::Adapter -e"Koha::Plugin::RMA::ItemHook::Adapter->new->install" etc. Do we really need a script for that? -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34335 --- Comment #14 from David Cook <dcook@prosentient.com.au> --- (In reply to Marcel de Rooy from comment #13)
Why not just call something like:
perl -MKoha::Plugin::RMA::ItemHook::Adapter -e"Koha::Plugin::RMA::ItemHook::Adapter->new->install"
etc.
Do we really need a script for that?
That's an overly simplistic example. For a more complicated example, you'd need to write a full custom Perl script. This change means you don't need a custom script. You can just pass in configuration/data. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34335 --- Comment #15 from David Cook <dcook@prosentient.com.au> --- If folk don't want it in core Koha, that's fine. I'm already using this pattern in existing plugins. I've found it useful and thought others would too. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34335 --- Comment #16 from Marcel de Rooy <m.de.rooy@rijksmuseum.nl> --- (In reply to David Cook from comment #15)
If folk don't want it in core Koha, that's fine.
I'm already using this pattern in existing plugins. I've found it useful and thought others would too.
I do not have a strong objection either. Just asking for some feedback. -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org