osTicket / osTicket-plugins

Core plugins for osTicket (v1.8+)
GNU General Public License v2.0
149 stars 162 forks source link

Wrong Plugin Instance ID inside Signal::send $callable function #257

Closed conandrum closed 1 year ago

conandrum commented 1 year ago

In osTicket version 1.17.2 we now have the capability for multiple plugin instances. Question: How can a $callable function, in a Signal::send, become aware of the Plugin Instance that invoked it?

This is the process as I understand it: The plugin's bootstrap function is called for each active plugin instance. class.plugin.php[201] foreach($p->getActiveInstances() as $i) $i->bootstrap();

Let's say we have 2 instances with ids: 31 and 32

Suppose now that the bootstrap function subscribes to a signal like so: e.g. Signal::connect('ticket.create.before', function($obj,&$data) {file_put_contents("log file path", echo $this->config->instance->id.',', FILE_APPEND);});

So $i->bootstrap(); is called for instance 31 and then for 32.

When Signal::send happens, the above $callable function is called. The problem is that it always echoes the LAST instance->id that was iterated in the foreach loop above (class.plugin.php[201]).

So it writes 32,32, in the log file.

Is there a proper way for the $callable function to acquire the right config and the instance id that caused it to connect to the signal in the first place? I am asking because ultimately each plugin instance will have its own configuration and I need to be able to distinguish between them.

Thanks

conandrum commented 1 year ago

Was answered in the forum here: https://forum.osticket.com/d/102299-wrong-plugin-instance-id-inside-signalsend-callable-function