MyBB Community Forums

Full Version: Plugin upgrade way
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello there,

I've a great question I didn't find the answer.
I'm working on a plugin I did, and the next evolution will modify templates and database. How can I do that properly ? I don't want my users uninstall and re-install the plugin, neither unactivate and reactivate.

The only way I found is to check if the required plugin parameters exists in the settings table, and if not do the alter of the table (insert new parameters) and change the templates. But it means that the check query will be called each time someone goes in the ACP plugin section (I'd put my check in the
_is_installed function).

Is there a better way ?

Regards
Really the best way that I've found is to require a deactivate and re-activate. It's not a massive problem for users of your plugin really.
(2014-10-07, 02:15 PM)Euan T Wrote: [ -> ]Really the best way that I've found is to require a deactivate and re-activate. It's not a massive problem for users of your plugin really.

For template update this works great. But for database updates Confused
I think you can add a hidden opt for plugin version and then on activate and deactivate routine you can add a conditional to get this value and not deactivate plugin. Only upload new files this read new adds on plugin opts then add a new button with opts to update only changes if this setting are present if wont make normal functionabillyty.

I only think to add this because i have before some experience on adding some values as my_plugin_opt_install and then activate, deactivate and this replaces custom texts but i prefer to use power or enabled.

I did not test but maybe can add a new button inside _info funtion too and add mew button like update and get values of version or a new function on this plugin and onclick run a method for some class or only some function to upgrade.

I think have to work.
(2014-10-07, 02:55 PM)TheGarfield Wrote: [ -> ]
(2014-10-07, 02:15 PM)Euan T Wrote: [ -> ]Really the best way that I've found is to require a deactivate and re-activate. It's not a massive problem for users of your plugin really.

For template update this works great. But for database updates Confused

I usually just write a function to handle that on activate if a cache key exists (euantor_plugins cache).
(2014-10-07, 05:00 PM)Euan T Wrote: [ -> ]
(2014-10-07, 02:55 PM)TheGarfield Wrote: [ -> ]
(2014-10-07, 02:15 PM)Euan T Wrote: [ -> ]Really the best way that I've found is to require a deactivate and re-activate. It's not a massive problem for users of your plugin really.

For template update this works great. But for database updates Confused

I usually just write a function to handle that on activate if a cache key exists (euantor_plugins cache).

This gave me an idea about how I do upgrade my plugin Big Grin Thanks Wink
Thanks for all your anwers.

My trouble is when the old version of the plugin has no particular info. It's true for my old plugins or for... one of @TheGarfield Big Grin
I think I'll now add a setting "version", and then each new version would have functions update($from, $to)... Seems to be the better way.

@TheGarfield: you'll have an update soon Smile
I added it to the cache, that way it's transparent to the user, and it doesn't disappear once the files are changed, so when you upload new files, the activate() routine will look if the cached version matches the plugin version, if not it will run through an "update" routine that I created.

I think that in MyBB 2.0, there should be an easier way to handle updates.

@Crazycat : Yes Big Grin