Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Method Override
Hi,
I've been playing with Vanilla2/Garden and looking at building some plugins for it. It's been a few years since I've worked with PHP so its a bit rusty for me at the moment.
One of the things I've been playing with is swapping out the search functionality for Sphinx or Apache Solr. I was looking to override methods in the search controller and search model from a plugin.
I was looking at declaring a methods called:
- SearchController_Index_Override
- SearchModel_Search_Override
- etc...
However, they never seem to get called... Digging in a bit further the only method I see that gets called and checks for an override during a request is the "Render" method (i.e. SearchController_Render_Override).
I may be missing the obvious, but does anyone else have any ideas or pointers?
Thanks.
Ben
I've been playing with Vanilla2/Garden and looking at building some plugins for it. It's been a few years since I've worked with PHP so its a bit rusty for me at the moment.
One of the things I've been playing with is swapping out the search functionality for Sphinx or Apache Solr. I was looking to override methods in the search controller and search model from a plugin.
I was looking at declaring a methods called:
- SearchController_Index_Override
- SearchModel_Search_Override
- etc...
However, they never seem to get called... Digging in a bit further the only method I see that gets called and checks for an override during a request is the "Render" method (i.e. SearchController_Render_Override).
I may be missing the obvious, but does anyone else have any ideas or pointers?
Thanks.
Ben
0
Comments
Maybe around Line 220 in class.dispatcher.php put in a check if its got a replacemement method, if so call it... I dont know the framework all that well at the moment, but putting in something like:
if ($PluginManagerHasReplacementMethod) { $PluginManager->CallNewMethod($Controller, $Controller->ControllerName, $ControllerMethod); }
Seemed to solve the problem. Maybe its worth also checking again, just after line 202, if there is a new method after the $ControllerMethod defaults back to Index if the controller method is not found (as the Index method maybe overridden by a plugin).
Note: My line numbers are based on a version checked out from github on 3rd December 2009.
When I'm done with this vBulletin importer, I have a bug on my radar that needs closing and then I'm going to turn some attention at search in general.
I have a very early proof of concept working that follows the guidelines of main and delta updates. - I want to make some bigger improvements then I'll drop you/the public a copy. I'll keep you posted with how I get on.
Maybe I should get myself setup on Github seen as thats where most things Vanilla/Garden seem to be getting done at the moment?
I'm using the following at the top of my plugin:
Gdn::FactoryInstall('SearchModel', 'SphinxModel', PATH_PLUGINS.DS.'SphinxSearch'.DS.'class.sphinxmodel.php', Gdn::FactorySingleton);
However, after putting a debug output on the FactoryInstall method of the "Gdn" class I see that the Garden SearchModel is installed prior to my custom one.
Anyone got any ideas or suggestions on any better ways I can achieve this? Should I be trying to override the base SearchModel, or am I opening a can of worms for future maintenance?
$tmp = Gdn::FactoryOverwrite(TRUE); Gdn::FactoryInstall('Gdn_SearchModel', 'Gdn_SphinxModel', PATH_PLUGINS.DS.'SphinxSearch'.DS.'class.sphinxmodel.php', Gdn::FactorySingleton); Gdn::FactoryInstall('SearchModel', 'Gdn_SphinxModel', PATH_PLUGINS.DS.'SphinxSearch'.DS.'class.sphinxmodel.php', Gdn::FactorySingleton); Gdn::FactoryOverwrite($tmp); unset($tmp);
Still not sure if its the right approach... I shall persue and see what I can come up with...