Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date sorting working improperly on production server #1910

Closed
ghost opened this issue Mar 12, 2018 · 3 comments
Closed

Date sorting working improperly on production server #1910

ghost opened this issue Mar 12, 2018 · 3 comments
Assignees
Labels

Comments

@ghost
Copy link

ghost commented Mar 12, 2018

I've just deployed a new site running Grav 1.4.0 and have experienced issues when sorting Page Collections by date.

When developing the site locally (on AMPPS 3.7), I ran into a different date sorting problem, which I reported (#1810) and has been fixed in 1.4.

However, once I moved the site onto the production server, the same sorting operations were producing very erratic results, for which I couldn't ascertain a pattern (it seemed like blocks of items were sorting correctly, but the blocks were out of order).

The fix for the production server was to undo the change made in #1810: switching date sorting from SORT_NUMERIC back to SORT_REGULAR. I'm sorting using the standard page.collection() method and also by running order() on an already retrieved page collection in Twig.

I assume this is a server configuration issue, but I don't know what to look for. Can you provide any guidance?

@rhukster
Copy link
Member

Oh the irony!!!! :) I think it probably makes sense to have a config option to toggle between these two sorting types. It seems you are running on some specific filesystems that are tripping up PHP sorting.

@ghost
Copy link
Author

ghost commented Mar 13, 2018

@rhukster You said it, especially as I waited until 1.4.0 released to deploy the website :-)

Having investigated further I'm thinking the issue is related to 32-bit vs 64-bit PHP: AMPPS (which I use for local dev) is 32-bit, and my web hosting server is 64-bit.

If this is the issue then rather than having a settings toggle (which is another thing to re-set when deploying, and then handle in version control) it may be better to switch out the sort flag dependent on platform bitness:

// PHP_INT_SIZE: 4 = 32-bit; 8 = 64-bit
$sort_flag = (PHP_INT_SIZE == 4) ? SORT_NUMERIC : SORT_REGULAR;

As a fallback, I'd say the default setting of the sort flag should be SORT_REGULAR, as its quirks would likely affect fewer sites (those that sort pages by date where the dates are before 1970, on 32-bit systems).

@ghost
Copy link
Author

ghost commented Mar 27, 2018

@rhukster After having a play with the buildSort() method from Pages.php I've found a combination of sort flags that works for both my local and server configurations. First, lines 1204-6:

case 'date':
    $list[$key] = $child->date();
    $sort_flags = SORT_REGULAR;

Then, lines 1279-81:

} else {
    asort($list, SORT_REGULAR);
}

I don't know how this would effect other sorts however.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant