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

edited December 2009 in Vanilla 2.0 - 2.8
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

Comments

  • It seems that the Dispatch method of the Gdn_Dispatcher class is not firing the new "override" method instead.

    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.
  • We were just talking about improving search: http://github.com/lussumo/Garden/issues#issue/175

    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.
  • @benno If you want to sign the contributor's agreement and share your code for integrating Sphinx, I'd be keenly interested
  • @Lincoln Thanks. I've signed the contributors agreement now. I'll happily share my code for integrating Sphinx, as I said, my PHP is a bit rusty but I'm more than happy to help with a common goal where I can.

    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 also seem to be struggling to override models, but I'll look into that more tomorrow, unless someone comes up with a suggestion as to how to do it, or a reason why you cant/shouldnt.
  • @benno Getting a GitHub account would be a good plan.
  • Still playing with a few bits. I'm trying to override the "SearchModel" in Garden, so I can take use the hooks throughout the other bits, like Vanilla for indexing new posts.

    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?
  • edited December 2009
    I figured it out how to do it (thanks to a sneak peak in the cssthemes plugin)...

    $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...
Sign In or Register to comment.