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

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?

Cheers,

Rob
 
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
PHP:
XenForo_Application::resetDynamicClassCache();
just to be safe...
 
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.
 
I'm now getting this error:-
Non-static method XenForo_Application::resetDynamicClassCache() should not be called statically
 
Grrr.... this is really grinding my gears.... lol!!!

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

   $app = new XenForo_Application;
   $app->resetDynamicClassCache();
   $noticeM = XenForo_Model::create('XenForo_Model_Notice');
   $noticeM->rebuildNoticeCache();
}

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.
 
If this doesn't work then there's an ugly hack:
after the query add something like:
PHP:
XenForo_Application::set('skipClassExtensionBlahBlahBlah', true);

and in the "rebuildNoticeCache" function that you created to extend XF's original one, add this at the very top:
PHP:
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:
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.
 
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.
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
 
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.
 
  • Like
Reactions: Rob
Top Bottom