Fixed Please retain the order of templates.xml entries between releases

Steffen

Well-known member
Affected version
2.0.5
The order of "template" entries in the templates.xml file shipped with XenForo doesn't seem to be deterministic. For example, the unified diff between the XenForo 2.0.4 templates.xml and the XenForo 2.0.5 templates.xml consists of 27886 lines although far fewer template lines have actually changed. It's just that the order of template entries is different from release to release.

Bash:
$ diff -ur xenforo_2.0.4_full/upload/src/addons/XF/_data/templates.xml xenforo_2.0.5_full/upload/src/addons/XF/_data/templates.xml|wc -l
27886

This does not cause any problems with Xenforo but if you keep XenForo in a Git repository (like I do) then this can be a little annoying.

And maybe the following simple patch is all that's needed (assuming that you use the export-templates command when building the XenForo ZIP file):

Diff:
diff --git a/src/XF/Cli/Command/Development/ExportTemplates.php b/src/XF/Cli/Command/Development/ExportTemplates.php
index a4edcb030..1572c5004 100644
--- a/src/XF/Cli/Command/Development/ExportTemplates.php
+++ b/src/XF/Cli/Command/Development/ExportTemplates.php
@@ -18,5 +18,6 @@ class ExportTemplates extends AbstractExportCommand
     protected function extraFinderConditions(Finder $finder)
     {
         $finder->where('style_id', 0);
+        $finder->order('type', 'title');
     }
}
\ No newline at end of file

I've written a custom command to sort templates.xml files after the fact but I'd greatly appreciate if this could be "fixed" upstream. :)
 
Last edited:
I'm sure I must have seen diffs of this file before and somehow not picked up on it. Thanks, added that for the next release.
 
Hang on... that code doesn't do what you think it does.

When we export our install data, we use the same command that normal add-ons run (which is called in the build-release command, though we don't use that directly).

The command we use is xf-addon:export XF which exports using the Template add-on data handler in XF\AddOn\DataType\Template.

There's already an order by title there, but similar to your diff above, I've added an ->order(['type', 'title']).
 
Top Bottom