Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: Mr. Pedram - kesäkuu 04, 2014, 04:02:47 AP

Otsikko: Drop table after uninstalling the mod
Kirjoitti: Mr. Pedram - kesäkuu 04, 2014, 04:02:47 AP
I working on a mod, it will install successfully and also uninstall perfectly but one thing will left behind, the table that mod created won't drop after mod uninstalled.

uninstall part:

Koodi (package-info.xml) [Valitse]
<uninstall for="2.0 - 2.0.99">
<modification reverse="true">install.xml</modification>
<database>uninstall.php</database>
</uninstall>


uninstall file for database:

Koodi (uninstall.php) [Valitse]
<?php
if (!defined('SMF'))
die('Hacking attempt...');

global 
$smcFunc;

$smcFunc['db_drop_table'] ('{db_prefix}mytesttable');
?>


what's wrong?
i see this happened before for other mod, like thank-o-matic or etc..
it's normal?! or i missed something?

no error from database/or/php
and tested on localhost, nothing in error log
Otsikko: Re: Drop table after uninstalling the mod
Kirjoitti: margarett - kesäkuu 04, 2014, 04:06:33 AP
You don't need to do that. As long as you create the table with adequate $smcFunc functions (and we will ask you to do it), SMF (2.0+) will log that and offer the user the possibility to remove it at uninstall. You don't need any code/database for uninstall.
Otsikko: Re: Drop table after uninstalling the mod
Kirjoitti: Mr. Pedram - kesäkuu 04, 2014, 04:46:09 AP
Lainaus käyttäjältä: margarett - kesäkuu 04, 2014, 04:06:33 AP
You don't need to do that. As long as you create the table with adequate $smcFunc functions (and we will ask you to do it), SMF (2.0+) will log that and offer the user the possibility to remove it at uninstall. You don't need any code/database for uninstall.

Oh, you right, now i remember that option..

LainaaRemove all data associated with this modification.

Thank you for answer.

Otsikko: Re: Drop table after uninstalling the mod
Kirjoitti: butchs - kesäkuu 07, 2014, 08:43:02 IP
With SMF 2.0 you will need uninstall code for "scheduled_tasks" and changing DB values to turn off a mod.

I have been uninstalling and re-installing a bunch lately and I noticed that with SMF 2.0 &  2.1 asking to drop mod tables seems to be an infrequent thing.
Otsikko: Re: Drop table after uninstalling the mod
Kirjoitti: Arantor - kesäkuu 07, 2014, 09:09:41 IP
If you're not being asked, you're probably not setting it up correctly in the first place.
Otsikko: Re: Drop table after uninstalling the mod
Kirjoitti: butchs - kesäkuu 08, 2014, 03:56:01 IP
Oh, it seemed that it asked one time.
Otsikko: Re: Drop table after uninstalling the mod
Kirjoitti: margarett - kesäkuu 08, 2014, 06:16:46 IP
One time, yes. Because at that time the tables/columns were in fact created.

If, at uninstall, you choose not to remove data, when you reinstall, those tables/columns will not be recreated and, as such, you will not be offered them again ;)
Otsikko: Re: Drop table after uninstalling the mod
Kirjoitti: Arantor - kesäkuu 08, 2014, 06:32:08 IP
That sounds suspiciously like a bug to me.
Otsikko: Re: Drop table after uninstalling the mod
Kirjoitti: margarett - kesäkuu 09, 2014, 07:08:37 AP
Really? That's how it always behaved for me so I thought of it as a feature, not a bug :P

Usually MOD installers only call $smcFunc with add column/add table if they don't exist already. So it they do exist already, that install will not create them and, as such, they are not logged for uninstall. Makes sense for me... Not?
Otsikko: Re: Drop table after uninstalling the mod
Kirjoitti: Arantor - kesäkuu 09, 2014, 07:10:54 AP
Consider the following situation:
1. Install mod.
2. Uninstall mod, not deleting data.
3. Install updated version of mod.
4. Uninstall mod, no longer desired.

Is the data now left behind without option to remove it?
Otsikko: Re: Drop table after uninstalling the mod
Kirjoitti: margarett - kesäkuu 09, 2014, 07:12:26 AP
Errr... Yes? :P

I see your point and of course it makes sense. It's just that it always worked like that for me (IIRC) so I got used to it.
Otsikko: Re: Drop table after uninstalling the mod
Kirjoitti: Arantor - kesäkuu 09, 2014, 07:13:49 AP
That's one of my central arguments... we have gotten too used to how things are that we no longer question whether it is correct that it should be so.
Otsikko: Re: Drop table after uninstalling the mod
Kirjoitti: margarett - kesäkuu 09, 2014, 07:15:24 AP
Point taken ;)