View Issue Details

IDProjectCategoryView StatusLast Update
0030792mantisbtapi restpublic2023-01-05 06:19
Reporterwebgarden Assigned To 
PrioritylowSeveritymajorReproducibilityhave not tried
Status acknowledgedResolutionopen 
Product Version2.25.5 
Summary0030792: Cannot get the currently executing plugin using an asynchronous REST API call
Description

Hello there,

I'm using EVENT_REST_API_ROUTES event to register a route within my plugin's route group.
Everything works perfectly besides the fact that Mantis (Slim?) isn't aware of the currently executing plugin within AJAX requests (plugin_get_current() returns null). This forces me to hardcode plugin's basename argument using the Plugin API.

Example code:

public function handleRestApiRoutes($event, $payload) {
    $plugin = $this;
    $payload['app']->group(plugin_route_group(), function ($app) use ($plugin) {
        $app->post('/votes', [$plugin, 'castVote']);
    });
}

public function castVote() {
    var_export(plugin_get_current()); // NULL
}
TagsNo tags attached.

Activities

webgarden

webgarden

2022-07-24 03:34

reporter   ~0066826

Last edited: 2022-07-24 03:39

I was able to fix this by running plugin_push_current($this->basename) inside the route callback routine.

The expected behaviour would be that this works OOTB and my plugin exists in the $g_plugin_current based on the plugin route group.

webgarden

webgarden

2023-01-04 07:55

reporter   ~0067257

It's still so frustrating... Anyone have any ideas? Am I doing something wrong?

dregad

dregad

2023-01-04 08:11

developer   ~0067258

I was able to fix this by running plugin_push_current($this->basename) inside the route callback routine.

This is what I do as well.

webgarden

webgarden

2023-01-05 02:22

reporter   ~0067259

Thanks @dregad, it's somehow comforting. I mean it.

For now I moved this logic into a middleware but I have an impression that this is more of a workaround than a desired solution.

dregad

dregad

2023-01-05 06:19

developer   ~0067260

I have an impression that this is more of a workaround than a desired solution.

I would tend to agree, but I'm not sure how to go about fixing this, and unfortunately I do not have the time to look into a better and more permanent solution.

I you have any ideas, your contribution would be welcome.