Record Sorting & Spontaneous Re-ordering

5 posts by 2 authors in: Forums > CMS Builder
Last Post: June 15, 2015   (RSS)

By Dave - June 11, 2015

Hi Jayme, 

Thanks for the report, I haven't heard of that one before.

How dragSortOrder works is when you add a record it sets the 'dragSortOrder' field to a large number such as 1434055505.

The number is actually 'unixtime' (the number of seconds since 1980).  So if you add one record a second each one will have a number one greater than the one before.  It also renumbers the existing records from time to time using increments of 10.

When you sort the default is ASC or ascending order, but you can also specify DESC for descending order.  So that will control if new entries get added to the top or bottom and reverse the order of any existing records.  Since you're sorting ascending (1,2,3) or descending (3,2,1).

If no sort order is specified on viewer getRecords calls it usually loads the sort order from the Section Editors config so everything matching up on the front and back ends.

I have a few suspicions about what could be going on.  Can you try adding this debug code to the plugin (it will show the current sort order on each record and the sort order that will be inserted): 

// create link
$addLink = "?menu=$tableName&action=add&dragSortOrder=$newSortOrder";
$actionLinks .= "<br/><a href='$addLink'>{$GLOBALS['CRH_LINK_NAME']}</a>";
$actionLinks .= "<br/>This order: {$record['dragSortOrder']}, Create as: $newSortOrder";

Next, can you let me know which version of MySQL they are running (listed under Admin > General at the bottom).

Also are they using the Save & Copy plugin as well?

Let me know what you find, thanks!

Dave Edis - Senior Developer
interactivetools.com

Hi Dave,

Thanks for the explanation of how this works. I always assumed that the order was more a simple index like what Joomla!/Mambo used to use. But the timestamp makes a lot of sense.

In answer to your questions:

1 - Yes, they are using both the createRecordHere.php plugin as well as the saveAndCopy.php/.js.php plugin. Plus there's a listRefreshFix.php which I've not noticed before.

2 - The server script versions are: PHP Version  PHP v5.3.29 -    Database Server  MySQL v5.5.3231.0 (Max Connections: 500)

3 - I've added the debug code to the plugin and it's now showing the current and proposed sort order. Not sure what you may need me to report beyond that. The current sort order is generally in DESC order from the samples I've looked at.

Looking forward to sorting this. It's become a serious issue for this client.

Jayme

By Dave - June 12, 2015

Hi Jayme, 

I'd recommend you ask the client to keep an eye on the "current sort order value", specifically look for when it has the same value as a record above or below (this might happen after using save & copy) .

Hopefully they'll notice a pattern and you'll be able to identify the plugin or process that is leading to the problem (which I suspect is identical sort orders on multiple records).

Let me know what they find, or if they see reordering for another reason.  We need to recreate it or get a sense of how it's happening to address it.

Dave Edis - Senior Developer
interactivetools.com

Thanks Dave. Understood.

Being able to see the sort order will make this a great deal easier to track.

Will let you know what we find.

Jayme