MyBB Community Forums

Full Version: Template System Changes [split] from PluginLibrary 6
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Ya know. I don't believe you're correct in how Template Versions work. In fact, I know you're wrong. The version on forumdisplay_threadlist_sortrating in my 1.6.5 database says 120. Which obviously not matched to the MyBB version. Thus your assumption is incorrect. When you edit a template, it changes the sid from -2 to > 0, thats how it knows it has been edited. So your entire methodology is 100% incorrect. As I said in my own thread about managing templates. I control my version numbers. Period. End of story. And it works. Yes, the version number is changed when you edit a template. However, it is the sid that is important here.

Here is the query in question:
	// Finds templates that are old and have been updated by MyBB
	$compare_version = $mybb->version_code;
	$query = $db->query("
		SELECT COUNT(*) AS updated_count
		FROM ".TABLE_PREFIX."templates t 
		LEFT JOIN ".TABLE_PREFIX."templates m ON (m.title=t.title AND m.sid=-2 AND m.version > t.version)
		WHERE t.sid > 0 AND m.template != t.template
	");

So, it doesn't compare just the version. As can be clearly seen.

Mine showed up just fine though. Of course, then to make it work, you keep the version tag assigned by your plugin to be equal or greater than the version of MyBB that is currently released. I would say greater, but thats just how I would do it. The easy option is to always insert the templates with MyBB Version + 1.
Oh, and ideally the version compare should just be removed from the query anyways, since it adds unnecessary complexity when we're tracking via the sid anyways.
(2012-01-19, 10:09 PM)Dylan M. Wrote: [ -> ]The version on forumdisplay_threadlist_sortrating in my 1.6.5 database says 120.

So it wasn't changed since MyBB 1.2?

Downloading MyBB 1.2.0, this is how it looked like there:

                <template name="forumdisplay_threadlist_sortrating" version="120"><![CDATA[<option value="rating" {$sortsel['rating']}>{$lang->sort_by_rating}</option>]]></template>

This is how it looks like in 1.6.5:

                <template name="forumdisplay_threadlist_sortrating" version="120"><![CDATA[<option value="rating" {$sortsel['rating']}>{$lang->sort_by_rating}</option>]]></template>

Which is exactly identical. It wasn't ever updated since, hence no change in the version number for that template.

(2012-01-19, 10:09 PM)Dylan M. Wrote: [ -> ]When you edit a template, it changes the sid from -2 to > 0, thats how it knows it has been edited.

The sid simply refers to the template set. Not related to versioning whatsoever.

(2012-01-19, 10:09 PM)Dylan M. Wrote: [ -> ]And it works.

No - it doesn't.

(2012-01-19, 10:09 PM)Dylan M. Wrote: [ -> ]The easy option is to always insert the templates with MyBB Version + 1.

If you set the version of the master template to MyBB version + 1, then whenever the user edits a template, it would keep showing up in "Find Updated Templates" as requiring an update. Since editing would give the template actually a smaller version than what is required by the master template.

The version number just can't be used the way you describe for plugin templates, not unless you change how MyBB itself works. For example if MyBB didn't blindly set mybb->version but used the actual master template's version, it would work with custom version numbers chosen for each template by the plugin author. It's a pointless exercise though - it works quite well with the current method as implemented by PluginLibrary. There is very little to gain with a more versatile versioning scheme - MyBB needs it for downloadable themes and stuff, but plugin templates are usually not included in those anyway.
It does so work, if you set your plugin template version to $mybb->version + 1 when its inserted, it works correctly. Always.

And no, sid has nothing to do with the template group. Nothing. When you edit a template the version is set to the current MyBB version, and the sid is changed to be greater than 0.

If you look at the update I just did to my tutorial, you'll find it works correctly. Always.
(2012-01-19, 10:36 PM)Dylan M. Wrote: [ -> ]It does so work, if you set your plugin template version to $mybb->version + 1 when its inserted, it works correctly. Always.

Nope.


(2012-01-19, 10:36 PM)Dylan M. Wrote: [ -> ]And no, sid has nothing to do with the template group. Nothing.

Correct. Please read my post. I said template set, not group, and no I didn't edit that afterwards.

When you edit a template for a given template set, it creates an entry in the templates table for that edited template - with the sid of that template set. Without the sid, when using multiple template sets (multiple themes), it wouldn't know which template set / theme the edited template would belong to.

(2012-01-19, 10:36 PM)Dylan M. Wrote: [ -> ]If you look at the update I just did to my tutorial, you'll find it works correctly. Always.

I didn't just look at it, I actually copied your code verbatim into a pluginname.php file (you have a syntax error in there by the way, you forgot , after mybb->version + 1), and as expected, it does not work. When you edit one of your templates, and use find updated templates, the edited template shows up in there. And that is not how it is supposed to be.

I'm not claiming that PluginLibrary's method is the best. I already pointed out its shortcomings. Maybe I'll find a way to improve it in the future. For now, it'll do.
Sounds like MyBB needs to definitely rethink versioning of templates in 2.0, if not in 1.6.6.

I now understand how the pluginlibrary is working as I originally missed the setting of version = 0 during an update.

However, I would like to propose a change that would allow the user to specify the version to use so the master templates can be set to use the plugin's version, though it may need to be a negative number so it still shows up in Find Updated when a plug version is greater than the MyBB version. It would greatly help in debugging.
(2012-01-19, 10:46 PM)frostschutz Wrote: [ -> ]
(2012-01-19, 10:36 PM)Dylan M. Wrote: [ -> ]If you look at the update I just did to my tutorial, you'll find it works correctly. Always.

I didn't just look at it, I actually copied your code verbatim into a pluginname.php file (you have a syntax error in there by the way, you forgot , after mybb->version + 1), and as expected, it does not work. When you edit one of your templates, and use find updated templates, the edited template shows up in there. And that is not how it is supposed to be.

I'm not claiming that PluginLibrary's method is the best. I already pointed out its shortcomings. Maybe I'll find a way to improve it in the future. For now, it'll do.

Blech, I forgot to consider that portion. I only had the template I edited before upgrading the forum to 1.6.5.
I guess I should just rework the existing template system to be smarter in MyBB 1.6.7, because this is annoying. Your way requires to much extra hoopla. If the system was changed to not change the version whenever a template is edited, and instead just change the sid (which yes, you're correct about that as well... though if you look at the query I posted above it does check for sid too, which had me confused because I didn't bother following the logic from start to fnish-bah!), then it would work fine. I'll discuss this with the team and see if there is a valid reason for changing the version that I'm not aware of. If there isn't, then I'll fix this.
(2012-01-19, 11:30 PM)pavemen Wrote: [ -> ]It would greatly help in debugging.

It'd also make it more complicated, whereas the current method works fine while keeping things simple. I'm not sure it'd really help with debugging - the version number is something that's completely hidden away, never displayed anywhere, but really only used for the Find Updated Templates and nothing else.

(2012-01-20, 12:01 AM)Dylan M. Wrote: [ -> ]I guess I should just rework the existing template system to be smarter in MyBB 1.6.7, because this is annoying.

I think a small change is sufficient, I suggested it earlier: When editing templates, instead of setting the edited template to mybb->version, set it instead to the version of the master template. That way it's gone from Find Updated Templates, nothing changes for MyBB templates (you can just keep using MyBB versions for those as you always have done), but plugins gain the ability to use their own arbitrary versioning scheme for each individual template.

There isn't much else you can do anyhow, change the way templates are stored too much and you risk breaking all sort of things.

If MyBB implements such a change I'll support it in PluginLibrary (*), assuming people are willing to accept that this feature will work only with newer versions of MyBB...

(2012-01-20, 12:01 AM)Dylan M. Wrote: [ -> ]Your way requires to much extra hoopla.

It doesn't really do any hoopla, setting version to 0 or 1 is hardly rocket science. If you want hoopla, look at the edit_core() function. Smile Besides, hoopla is fine to a degree as long as it works and it's hidden away in a reusable library. Beats having each plugin implement its own semi broken logic with custom queries anyway.

(2012-01-20, 12:01 AM)Dylan M. Wrote: [ -> ]and instead just change the sid

It can't be changed - that'd be like changing the tid when posting a reply - the sid is locked to the template set.

* Don't expect too much of version numbers though. The changes in functionality would be minimal. If used, Find Updates Templates would work for imported themes/templates (rare case in my opinion), and PluginLibrary would use the version number rather than the template itself as criteria for a change of template, so plugin authors could do silent updates of templates (which should really only be used for whitespace changes or sth). In practice I don't see many cases where this would be relevant; I think the current system will do fine.
The SID should not change, in fact it never does. A new record with the correct SID for the current template set is created when editing a previously unedited template. otherwise you loose your master templates once you first edit a template.

If you are going to change the template editing system, it should be a fairly significant update, or don't bother.

I would suggest that in 1.6.7 you add a new field to the template table that is:

user_version int(5) default 1 not null

then modify the template editing code so that the version field is not modified unless the template does not exist for the current template set (thus coming from master set) so it can be shown as being derived from a specific master version.

I would like to see an option to SAVE NEW and SAVE EXISTING. New would increment the user_version and create a new copy/record of the template, Existing would not be an option if we are editing a previously unedited template (directly from master) and when enabled, would simply update the existing template contents and leave the user_version unchanged so we can keep the database size down.

This would require updating several areas such as importing, but since the default value of the user_version field is set, the existing theme exports should still work.

Exporting would not need to be changed either, as the user_version should be forced to 1 for any other person importing it.

Support for defining what versions to DIFF would be nice, but not required.

Reverting should be "to master" or "to previous" as options.
Quote:If you are going to change the template editing system, it should be a fairly significant update, or don't bother.

I'm all for don't bother then since there's very little to gain from it... Maybe the "change how the template system works" discussion could be moved to a new thread - this seems to be going into a direction too far removed from PluginLibrary.
Pages: 1 2