Basically there was a change in CMS 6 R2 which changed how sort orders are handled. When PageTypeBuilder is synching it will compare whether the page definition is different to the one stored in the database and if so it will update it.
In CMS 6 R2 a new method is now called named EnsureUniqueFieldOrder within the Save method of the PageDefinition.
At a high level this method does the following:
Checks whether the sort order for the current page definition matches the sort order of any other page definitions for the page type and if it does it will set a new value for it.
If a sort order has not been defined and there are existing page definitions it will get the highest sort order and add 1 to it.
This then has a potentially huge knock on effect because the next time the application starts PageTypeBuilder will go off and work it’s magic, but because the EnsureUniqueFieldOrder method has changed some of the sort orders, PageTypeBuilder will determine that the page definitions are different and update the definitions again .
So to put simply this is not a bug in PageTypeBuilder or EPiServer it’s just a unfortunate side effect of not defining your Sort Order's in your page types or specifying duplicates. Over time we often have many common base classes that page types will inherit from and can often be a case for many duplicates.
Some of you may be aware that I spend a lot of time commuting to and from London town and that I like to fill this time with knocking together useful modules and applications.
So last week to fill this time I decided to knock together a little console application which will scan a bin folder and tell you which page types have duplicate and undefined properties.
It can also fix all of the page type files for you (assuming you are programming in C#) and apply new sort orders for various property definitions including property groups. The fixing code will also fix sorting on page type and property group base classes too to ensure there are no duplicates.
Firstly you will need to Download the executable and it’s config file from here and dump it in a folder on your machine. Then you need to follow the steps below:
1. Re-build your application to make sure all of your assemblies are up to date. 2. Backup any relevant EPiServer databases and source files
3. Then you can execute the tool with the following arguments to determine which properties have duplicate or undefined sort orders.
5. Now that your files have been fixed, you will need to rebuild the solution. It may be possible that some classes/properties will not be updated, but this would probably be because of bad coding style, not by me of course
Now we have rebuilt we can run the tool again to check for duplicates and unassigned sort orders.
This will create a .sql file with the necessary SQL to reset all PageTypeBuilder Property Definition sort orders to 0, so you will need to execute the SQL against your database.
7. Now that sort orders have been reset you can run your application.
If you have a large number of page types and page definitions this initial update may take a bit longer than expected, but once this initial update is complete all future deployments/application restarts should be much quicker .
Checking Sort Orders on post build event
You can hook the sort order checking executable into your application build by calling it on a post build event, it's not particularly elegant but will fail the build if there are duplicate or undefined sort orders and will output duplications and undefined properties on page types to the output window.
Although I have done testing around this there could be possible side effects. I take no responsibility for any adverse affects. So basically use at your own risk and backup your database and source code first.
Please feel free to email or twitter me with any feedback @croweman