MyBB Community Forums

Full Version: Best way to update plugins?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
(2012-07-06, 05:54 AM)Jazza Wrote: [ -> ]
(2012-07-06, 05:52 AM)pavemen Wrote: [ -> ]If plugin developers would follow a standard then it would be less of an issue. My "standard" is:

Activate:
- change templates to make plugin content visible
- run upgrade script I include with some plugins
- update custom cache with latest version

I'm liking this idea of running an upgrade script with every activation, just to be sure.

when I use an upgrade script, I work with a custom cache that stores the version of the plugin, looks like this

Array
(
    [versions] => Array
        (
            [quote_notice] => 1.1
            [adminnotice] => 1.1
            [afv] => 1.3
        )

    [afv] => Array
        (
            [last_add_scan] => 1340310640
        )

)

upon activation i check the cache for the current version, run the upgrade script, then update the cache version. the upgrade uses this:

    	if(version_compare($oldver, '1.8.1', '<') && $oldver <> '' && $oldver <> 0)
    	{
		//do changes here
	}
    	if(version_compare($oldver, '2.0.2', '<') && $oldver <> '' && $oldver <> 0)
    	{
		//do changes here
	}	

so it can process the incremental changes regardless of the users installed version

finally I upgrade the cache to the new version for next time
Is this cache system already in place in MyBB? I've never heard of it (in terms of forums).
(2012-07-08, 11:20 AM)Jazza Wrote: [ -> ]Is this cache system already in place in MyBB? I've never heard of it (in terms of forums).

The DB 'datacache' table* holds all the default caches** and devs can add new entries related to their plugins***
*You can also use files, or memecache, etc. by changing ./inc/config.php

**Note that the data in the file ./cache/templates/global.css and ./inc/settings.php is what "actually gets served", not what's in the database; If you go directly into the db and make certain changes, then they don't 'go live' right away.
***Q) Paveman's custom cache is stored where? A) Either he will see this and answer, or just check his plugins to learn that. Toungue
Checking other people's plugins? No time for that! Toungue

I shall have to do some testing with caches. I've only just started writing a few plugins (one for notifications, one for featuring videos and images in templates, and some smaller ones).
You can already use the cached data of your forum (ACP -> Maintenance -> Cache) in your plugins.

For example, $cache->read('icons) will read all the icons in your forum for you, since they are saved in the cache (I have seen many plugins querying the DB for such data when it is already available).

You can "create" your cache using $cache->update('somekey') (will create if the first time) but you can only delete it with a delete_query.

There are some plugins that do what pavemen, newpoints and mynetwork for example. And there are other ones that cache far more data, like xThreads does.
Is there any instance where you shouldn't cache data in plugins?
IMO you should only cache data when it is better that a query, I did the mistake to cache almost all kind of data in my awards plugin. You have to consider that the cache is loaded in every MyBB page.

The Page Manager for example, caches every page, which may not be the best option.
I use the built-in MyBB cache handler to store versions and minor things that I need to track, like the last run time for my Advanced File Verification plugin.

Its definitely not for large persistent storage, however I do use it for moderate sized content in MyBB Publisher. That is usually debug or error messages and the latest versions allow you to clear those logs from the cache.
For now I'm rolling with what I currently have, which is adding database tables/columns with installing and adding settings with activation. It's not a great method, but I don't have the effort to change it at this time. When I have some more time to sit down and work with plugins (or maybe for my next plugin) I'll try switching to what you guys have recommended.

Thanks guys for your help. Good to know plugin authors are here to help out new plugin developers such as myself.

I hope to release some of my plugins in the near future. Smile
Here's a update on this. I've written a upgrade script that I'm now using with my plugins. The script modifies the database as much as it can, then adds any missing settings and templates. It's simple, but it works!
Pages: 1 2 3