Summary: | Run Koha plugin method from CLI | ||
---|---|---|---|
Product: | Koha | Reporter: | David Cook <dcook> |
Component: | Plugin architecture | Assignee: | David Cook <dcook> |
Status: | In Discussion --- | QA Contact: | Testopia <testopia> |
Severity: | enhancement | ||
Priority: | P5 - low | CC: | jonathan.druart, m.de.rooy, paul.derscheid |
Version: | Main | ||
Hardware: | All | ||
OS: | All | ||
See Also: | https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=28499 | ||
Change sponsored?: | --- | Patch complexity: | --- |
Documentation contact: | Documentation submission: | ||
Text to go in the release notes: | Version(s) released in: | ||
Circulation function: | |||
Attachments: |
Bug 34335: Add a script to run Koha plugin methods from the CLI
Bug 34335: Add a script to run Koha plugin methods from the CLI test plugin Bug 34335: Add a script to run Koha plugin methods from the CLI Bug 34335: Add a script to run Koha plugin methods from the CLI |
Description
David Cook
2023-07-21 01:07:07 UTC
*** Bug 26169 has been marked as a duplicate of this bug. *** Created attachment 153746 [details] [review] 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. It might be nice to be able to handle method parameters as well... maybe I'll have a little look at that... Created attachment 153747 [details] [review] 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 Created attachment 153748 [details]
test plugin
Created attachment 153749 [details] [review] 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 Passing quoted values to koha-shell kohadev -c "" doesn't work so well... so might need to have alternate ways of providing the params (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... This is indeed awesome. Created attachment 153760 [details] [review] 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 ;) Can you provide some use cases? (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. 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? (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. 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. (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. |