News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Use <database> tag?

Started by alex_qrlogin, November 05, 2017, 06:02:44 AM

Previous topic - Next topic

alex_qrlogin

Hi all,

I need help.
If use <database> tag in the deinstall section, the code placed in it is not executed - the table is not deleted. Why?
Can indicate an example of use?

And the second question: is there an analogue of a wordpress nonce in smf?

Arantor

You use <database> on install along with the proper $smcFunc['db_create_table'] statement and on uninstall SMF will ask the user if they want to delete data on uninstall and auto clean up the tables.

You can then also use <database> for the optional stuff to be deleted if the user said "delete all the data"

If you want to force it to be deleted, use <code> instead as this will run regardless on every uninstall.

alex_qrlogin

That is, the <database> is not needed when uninstalling?
Can not you show a mod using this as an example?

In <code> function drop_table not available((

Arantor

It is not needed when uninstalling if you set it up correctly, because for most cases you don't need it. Most mods have no need to explicitly clear out their data because most of the time the user will be uninstalling to add a newer version. Or if they're uninstalling to remove it, there's the option to explicitly clear out.

A mod that uses this for very complicated stuff, SimpleDesk. It has an installer which makes tables with install.php, then <code> calls uninstall-required.php for stuff that has to happen on every uninstall (like removing hooks), and <database> calls uninstall-optional.php for the additional stuff that can be cleared out if the user requests it.

As for it not working in <code>, call db_extend('packages'); to load the additional helper stuff.

alex_qrlogin

Thank you very much.)
Now I'll figure it out))

And what about my second question? An analogue of Wordpress nonse?

Arantor

I don't use WordPress, what exactly do you mean?

alex_qrlogin

https://codex.wordpress.org/WordPress_Nonces

»A nonce is a "number used once" to help protect URLs and forms from certain types of misuse, malicious or otherwise. WordPress nonces aren't numbers, but are a hash made up of numbers and letters. Nor are they used only once, but have a limited "lifetime" after which they expire. During that time period the same nonce will be generated for a given user in a given context. The nonce for that action will remain the same for that user until that nonce life cycle has completed.»

In wordpress plugin i use it in ajax & post from phone))


Arantor

SMF 2.1 has better support for this, but in 2.0 you'll need to pass around an item in the URL (or in a hidden <input>) where the name of the value is stored in $context['session_var'] and the value in $context['session_id'].

This is why you'll see various links that have ';' . $context['session_var'] . '=' . $context['session_id'] in them and similar.


Advertisement: