1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to run code after an add-on is fully uninstalled?

Discussion in 'XenForo Development Discussions' started by Rob, Jul 22, 2015.

  1. Rob

    Rob Well-Known Member

    When uninstalling a mod I've created, I need to recache information in the dataRegistry, but only after the mod's listeners have been removed.

    Is this possible inside my mod's uninstall callback?


  2. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    The latest version (1.5?) moved the callback after removing the master data so yeah the listeners are removed removed before the uninstall is called.
    And if you plan to call an object that is resolved dynamically, call
    just to be safe...
  3. Rob

    Rob Well-Known Member

    Ok, was this removed on beta 3?

    I'm asking because beta 2 threw errors after calling rebuildNotices, on the Notices model.
    It was trying to run the extended rebuildNotices function from the mod I was uninstalling, instead of the native one in the model.
  4. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    Include the reset function mentioned above and try again. And the code has been moved in Beta 1 I suppose.
  5. Rob

    Rob Well-Known Member

    I'll give that a whirl :)
  6. Rob

    Rob Well-Known Member

    I'm now getting this error:-
    Non-static method XenForo_Application::resetDynamicClassCache() should not be called statically
  7. Rob

    Rob Well-Known Member

    Grrr.... this is really grinding my gears.... lol!!!

    Here's the latest uninstaller
    public static function uninstall() {
    $db XenForo_Application::get('db');
              ALTER TABLE `xf_notice` DROP `noticeClass`

    $app = new XenForo_Application;
    $noticeM XenForo_Model::create('XenForo_Model_Notice');
    This fails dismally, saying that noticeClass is an undefined index - so it's still trying to run the notice model extended in my mod, as opposed to the default model. @Mike can you shed any light on this? I've googled resetDynamicClassCache and there is precious little information on it.
  8. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    If this doesn't work then there's an ugly hack:
    after the query add something like:
    and in the "rebuildNoticeCache" function that you created to extend XF's original one, add this at the very top:
    if (XenForo_Application::isRegistered('skipClassExtensionBlahBlahBlah')) return parent::rebuildNoticeCache;
    P.S. "XenForo_Application::resetDynamicClassCache()" is a static method :p
    Oops... it's a non-static method... lol
    Last edited: Jul 22, 2015
  9. Rob

    Rob Well-Known Member

    yeah... but @Rob is a php nooblet! :)

    I'll give that hack a whirl :p
  10. Chris D

    Chris D XenForo Developer Staff Member

    How important actually is it to rebuild the Notice cache in this case? As long as you haven't removed any data we would usually use to display Notices, it should be fine to leave it.
  11. Rob

    Rob Well-Known Member

    Yeah..... you da man! :)

    ... off to make a mod release :)
  12. Rob

    Rob Well-Known Member

    Are you sure? And here's me trying to do a proper clean up after myself. I've learned this as a direct opposite from some of the worst mods I've ever had the misfortune to pick apart when they've not uninstalled properly-ium (cryptic-ium!).

    If there are no ill effects from leaving it there then I'll just leave it there :D
  13. Chris D

    Chris D XenForo Developer Staff Member

    There are definitely cases where I would say a clean up is 100% necessary.

    There is a slight potential for confusion in the event that your add-on is uninstalled and reinstalled. That cached data would still be in there, e.g. if someone has a notice with a class of "custom" that class will be in the cache, but it won't be visible when editing the notice.

    Probably edge case enough to not worry too much about it.

    It's up to you whether you would class that as an "ill effect" or not :)

    The notice cache can be easily rebuilt automatically as soon as any notice created/saved.
    Rob likes this.

Share This Page