database vs code tag for installing/uninstalling mod

Started by Carceri, April 23, 2011, 04:36:16 AM

Previous topic - Next topic

Carceri

I have read whatever I can find on these forums about the difference between using <code> and <database> for installing/uninstalling a mod. I create a few entries in the modSettings array during installation, as well as registers a hook for integrate_general_mod_settings. That works whether I put this code in the <code> or <database> tag during installation.

When the mod is uninstalled, however, I want to delete these settings and unregister the integrate_general_mod_settings hook. If I put the corresponding code in the <code> tag, everything works as expected, whereas it doesn't get executed if it is put in the <database> tag.

As far as I can see, the <database> only gets executed if the user selects to purge all settings during uninstall, but I don't see that option during uninstallation. Probably because I didn't alter or add any database tables?

No problem... I can just use the <code> tag, but then I read somewhere that it is deprecated for SMF 2.0.

What am I supposed to do in this case?

NanoSector

You should use <database>, since it clearly states that it is properly gonna use the database :P
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

Carceri

Quote from: Yoshi2889 on April 23, 2011, 04:48:11 AM
You should use <database>, since it clearly states that it is properly gonna use the database :P

Well, thanks... but database doesn't allow me to do what I want :P

NanoSector

Quote from: Carceri on April 23, 2011, 04:58:38 AM
Quote from: Yoshi2889 on April 23, 2011, 04:48:11 AM
You should use <database>, since it clearly states that it is properly gonna use the database :P

Well, thanks... but database doesn't allow me to do what I want :P
If you use both the <database> tags on Installation and Uninstallation, it should probably give you the checkbox.
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

Arantor

Quote from: Carceri on April 23, 2011, 04:58:38 AM
Quote from: Yoshi2889 on April 23, 2011, 04:48:11 AM
You should use <database>, since it clearly states that it is properly gonna use the database :P

Well, thanks... but database doesn't allow me to do what I want :P

<database> can do everything that <code> can do, plus it has the ability to log what's done in the database to offer the user the ability to uninstall it after. But it has one quirk, as you've found.

The difference is, <database> in uninstall is only run if the user requests it be run, so you need to use <code> in the uninstall to purge hooks.

FWIW, SimpleDesk has an installer (in <database>), and two separate uninstall scripts, one that must be run every time (in <code>) and one that's only run when the user requests things be removed (in <database>)

You can do just about everything you'd ever want with a little creativity.
Holder of controversial views, all of which my own.


Carceri

Quote from: Arantor on April 23, 2011, 08:50:29 AMThe difference is, <database> in uninstall is only run if the user requests it be run, so you need to use <code> in the uninstall to purge hooks.

Thanks for the info.

But since <code> is the only place where hooks can be purged automatically at every uninstall (which is what you want), why is <code> then deprecated in SMF 2.0? For me it seems that both are still needed.

Arantor

Because when 2.0 first entered RC status, the hooks in their present form didn't exist. The hooks actually being used for the purposes that they are, as well as the add and call functions, well they didn't exist until 2.0 RC4. (Imagine: prior to 2.0 RC4, each hook could only support a single function, several of the hooks didn't even exist, as they were for integration to external systems, rather than loose extension for mod purposes)

So, previously, it was described as deprecated, but I think it can't safely be called that these days.
Holder of controversial views, all of which my own.


Carceri


Advertisement: