Topics

Anahita Project

Anahita Project's Topics

Nick Swinford

Nick Swinford

May 01 2018

Problem with Plugins

I just submitted a pull request to fix system plugins (https://github.com/anahitasocial/anahita/pull/484).

As I previous brought up here (https://www.getanahita.com/topics/163514-component-events), there's an issue with plugin events. The problems are two-fold.

The first one is easy enough to fix. None of the plugin events are happening early enough in the process cycle; atleast for my use cases. This is why behaviors aren't being added and aliases aren't being created. By the time onAfterDispatch has fired, every things already completed. To solve this, I created a new event, onBeforeDispatch and added it at the begging of ComApplicationDispatcher::_actionDispatch and voila, it works.

The truly ideal solution for this in my mind would be a new event called onAfterInitialise that fires as soon as all the necessary files and classes are included and instantiated. I tried adding this to the end of ComApplicationDispatcher::_initialize, but that caused an error so I'm not sure where the best place would be.

The second issue is more complicated. It looks like @Rastin already ran into this issue and tried to fix it here (https://github.com/anahitasocial/anahita/commit/adecc919c326be5c2c32659036c0c264dd07a034#diff-2166c1b5fe691e3551993bc46ec87330R68).

When the storage plugin is loaded via the system plugin, it calls LibPluginsHelper::import, loads all the plugins from the database, then iterates over all of them. When it finishes, it goes back to finish the first iteration of $this->_plugins for system plugins, but the array pointer is already at the end and finishes. No plugins after plgSystemAnahita get loaded.

It looks like this was attempted to be fixed by removing KService::get('plg:storage.default') from plgSystemAnahtia, but when $this->_viewer is set to the current viewer in plgSystemAnahita (https://github.com/anahitasocial/anahita/blob/master/src/plugins/system/anahita.php#L51), the effect is the same. The actor entity is created, then the storable behavior is loaded which triggers the importing of the storage plugin.

By moving $this->_viewer into the dispatch event, it takes it out of the import cycle and it allows all the system plugins to be loaded.

Much appreciated, I'll take a look!
@rastin, I've updated the topic with an explination. Hopefully you can understand me. 😜

Powered by Anahita