I am improving my modification by adding database actions, I have absolutely no idea how to use uninstall using <database></database>
File need sql file? Example:
DELETE FROM {db_prefix}settings WHERE variable LIKE 'magnet_%';
DROP TABLE IF EXISTS {db_prefix}Mag_Hashes;
DROP TABLE IF EXISTS {db_prefix}Mag_Clicks;
DROP TABLE IF EXISTS {db_prefix}Mag_IPBanList;
Or php code?
if (file_exists(__DIR__ . '/SSI.php') && !defined('SMF'))
require_once __DIR__ . '/SSI.php';
elseif (!defined('SMF'))
die('<b>Error:</b> Cannot uninstall - please verify you put this in the same place as SMF\'s index.php.');
$smcFunc['db_query']('', "DELETE FROM {db_prefix}settings WHERE variable LIKE 'magnet_%'");
$tabeli_do_usuniecia = array(
'Mag_Hashes',
'Mag_Clicks',
'Mag_IPBanList'
);
foreach ($tabeli_do_usuniecia as $tabela)
{
$smcFunc['db_query']('', 'DROP TABLE IF EXISTS {db_prefix}' . $tabela);
}
This is what I find on the wiki:
<database></database> or <database /> (for use with type="file" only)
Filename of a database code to be executed.
Only exists in SMF 2.0 or higher
Optional: Yes
Attributes:
type: "inline" or "file"; defaults to "file"; optional
But nothing works for me, I looked in the ultimate menu and it works there, some tables appear when uninstalling. And nothing works for me, I don't know why.
As for the php code, I see that in the database they are in lower case, but I tried what I gave as an insert and what is in the database.
<database> is only called if 1) you used a <database> to install it AND 2) the user selects to delete things when uninstalling.
The tag, <database> points to a file inside the package bundle to be called when the above is the case.
If you want to remove things when a user uninstalls, regardless of whether they might want to keep things (e.g. in case of uninstall ahead of an upgrade), <code> does something similar.
The SimpleDesk mod is an example of how to do this, it demonstrates using <database> during install, plus both <database> and <code> on uninstall to do both required and optional clean-up.
Quote from: Arantor on August 08, 2024, 05:35:10 PM<database> is only called if 1) you used a <database> to install it AND 2) the user selects to delete things when uninstalling.
The tag, <database> points to a file inside the package bundle to be called when the above is the case.
If you want to remove things when a user uninstalls, regardless of whether they might want to keep things (e.g. in case of uninstall ahead of an upgrade), <code> does something similar.
The SimpleDesk mod is an example of how to do this, it demonstrates using <database> during install, plus both <database> and <code> on uninstall to do both required and optional clean-up.
Example, and I think I'm doing it correctly, does modifying the table affect it? I have to make a separate modification because there were problems with its creation. (unless smc restrictions)
$indexes = array(
array(
'type' => 'primary',
'columns' => array('id')
),
array(
'name' => 'unique_link_ip',
'type' => 'unique',
'columns' => array('link_id', 'ip_address', 'msg_id')
),
);
$smcFunc['db_create_table']($db_prefix . 'Mag_Clicks', $columns, $indexes, array(), 'ignore');
$smcFunc['db_query']('', '
ALTER TABLE {db_prefix}Mag_Clicks
MODIFY COLUMN click_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL'
);
I forgot to add that, cleaning settings work well. Simply deleting tables doesn't work. (Mag_Hashes, Mag_Clicks, Mag_IPBanList)
After more research on community search I try also use $smcFunc['db_drop_table']: (also not work)
$tabeli_do_usuniecia = array(
'mag_hashes',
'mag_clicks',
'mag_ipbanlist'
);
db_extend('packages');
foreach ($tabeli_do_usuniecia as $tabela)
{
//$smcFunc['db_query']('', 'DROP TABLE IF EXISTS {db_prefix}' . $tabela);
$smcFunc['db_drop_table']('{db_prefix}'. $tabela);
}
Are you ticking the box that says to delete content when uninstalling? Because that's the *correct* process.
<database> is only invoked on uninstall if that box is ticked. AND if you actually did the install correctly (not mixing case on the table names, do everything lowercase), tables added during install will be properly removed because that's tracked. But {db_prefix}Mag_Clicks and {db_prefix}mag_clicks are not the same thing.
Again: use <code> for things that *must* be removed, use <database> for things IF THE USER SELECTS THEY WANT THINGS REMOVED.
Idk why but on my MOD this isnt be visible:
(https://i.ibb.co/6Y6yNbK/image.png)
But example ultimate-menu show me it, but he use DELETE FROM {db_prefix}settings not new added table.
(https://i.ibb.co/MpDtPFx/image.png)
Also, I tried all his code with overwriting my table names in the database and it doesn't work.
Are you using the <database> tag on install?
you might need to reinstall that mod once you ensure that <database> is executed in <install> to see that checkbox
Quote from: Arantor on August 08, 2024, 06:35:15 PMAre you using the <database> tag on install?
Quote from: live627 on August 08, 2024, 09:27:03 PMyou might need to reinstall that mod once you ensure that <database> is executed in <install> to see that checkbox
Wow it works. I couldn't find this information, thank you very much. Would you like to review the code related to the database so that people do not encounter problems, including security?
If you are talking to
@live627, note his signature.