MyBB Community Forums

Full Version: Updating plugins without data loss
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am currently in the progress of writing my first plugin, and I can't find any documentation about how I should design the 'update' process without data loss.

For example: I currently add my plugin setting group and my settings rows in the _install() function. If I add a new settings row and update the plugin version, how can I design the update process?  As I understand it, the admin needs to uninstall and install the plugin to create the new settings. But this will trigger my _uninstall() function, resulting in the deletion of all user data.

How are the other devs handling this? Do I need to design a special function which is called every time, just to check if my settings rows needs updating (by checking if they exists and create the missing ones)?
plugin should consist of deactivation function which should not delete the stored data.
uninstall function should remove stored data. [see this thread - it can be of some help]

see also MyBB Plugins Explained & advanced plugin development
(2015-05-27, 10:10 AM).m. Wrote: [ -> ]plugin should consist of deactivation function which should not delete the stored data.
uninstall function should remove stored data.  [see this thread - it can be of some help]

see also MyBB Plugins Explained & advanced plugin development

Thanks for your answer. My plugin already uses the _activate() and _deactivate() functions, but (as the documentation recommends) I do not alter any tables when (de)activating.

My question was how I should design the update process, when the admin is installing a new version of my plugin. As there is no _update() function, in which I could modify the plugins settings rows in the database, I am not sure how to do this.
What I did for a plugin was include a hook to admin_config_plugins_begin and run my function there that updates the plugin. You can make the page easily accessible by linking to it in the plugin description field.

This is an example of how one of my plugins uses it: https://github.com/dragonexpert/Advanced...y.php#L177
I insert/update settings on activate, and delete them on uninstall. All of this is managed automatically by PluginLibrary, which is why I use it for all my plugins - it saves a TON of time and effort.
I think the most usable is like Euan T says, on activate and deactivate function, you can use cache to set values and a new functions inside another to set values lesser or equal then do something or won't.

I use this on ThankYouMyBB plugin but sometimes users as ever run many times deactivate and activate or instaall and uninstall aa few times thinking magic can be done !!! aaand aautomatically plugins works if you run some times this proccess, i doubt it because only you have to work with hooks or sometimes haave to reactivate in some cases when some functions haave a conflict between and MyBB set a value automatized by priority on execution i think, but i dunno really.

I think the best way is using cache to set on that value the version of plugin and on uninstall and only uninstall clean all data including cache, i use in this plugin as well on lasat version and works like a charm, because only works if need Big Grin