[Bug 37431] New: A way to access the Plugin itself from a Mojolicious Controller
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=37431 Bug ID: 37431 Summary: A way to access the Plugin itself from a Mojolicious Controller Change sponsored?: --- Product: Koha Version: unspecified Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: Plugin architecture Assignee: koha-bugs@lists.koha-community.org Reporter: tadeusz@sosnierz.com QA Contact: testopia@bugs.koha-community.org While a Koha::Plugin has handy builtins for configuration in the form of store_data() and retrieve_data(), these are not easily accessible from the Mojolicious controllers that we configure in `api_routes()`. My use case specifically is allowing the plugin users to configure an API key in the Plugin (using `configure()`), and then using that API key in the Mojolicious controller. The way to accomplish this currently is manually instantiating the plugin in the controller and using that for the lookup as so: `Koha::Plugin::MyOrg::MyPlugin->new->retrieve_data(...)` This does not feel like a good solution since it's hard to say how Koha will react to us instantiating a Plugin multiple times without reading the code. It seems harmless for now, but there's no guarantee that it won't break something in the future. Ideally I'd see the alternative as something akin to https://metacpan.org/pod/Mojolicious::Controller#app method which currently that gives us a Koha::REST::V1 instance. I'd like to have a `plugin()` available in there as well, so that I could do a `$c->plugin->retrieve_data()` in my routes. Not sure how an implementation of that would look; perhaps there are better alternatives? -- 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=37431 Julian Maurice <julian.maurice@biblibre.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |julian.maurice@biblibre.com --- Comment #1 from Julian Maurice <julian.maurice@biblibre.com> --- You can use: Koha::Plugins::Datas->find("Koha::Plugin::MyOrg::MyPlugin", $key)->plugin_value Not ideal but better than instantiating the plugin twice. A mojo helper would still require you to give your plugin name as one of the helper's arguments, right ? Not sure how we can avoid that. -- 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=37431 --- Comment #2 from HKS3 Tadeusz Sośnierz <tadeusz@sosnierz.com> --- Not sure how to do that specifically either, but it feels like it should be possible since Koha "knows" which Plugin caused this particular Controller to be instantiated/called. Not sure if that is something that Koha keeps track of or has readily available. But afaik it is true that we have a one-to-many mapping between plugins and plugin controllers, so a controller always "belongs" to one particular plugin – so a $c->plugin or $c->app->plugin should be unambiguous. -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org