Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
With the introduction of #970950: Per-relationship default sort, sync of sorting algorithm between views and navigator, an inconsistency was introduced. Now all pages use the sort defined by the user *EXCEPT* for the Manage Images tab, which still uses the hardcoded ORDER BY.
This patch extrapolates the code that pulls the SQL off the view into a function, and also optionally strips the filters and sorts from the view object before running the query and returning an array of nids.
Comment | File | Size | Author |
---|---|---|---|
ng3-use-views-for-all.patch | 4.75 KB | justintime |
Comments
Comment #1
scroogie CreditAttribution: scroogie commentedHa, I just noticed this when testing out the navigator patch. Somehow the order switched around. Great catch. Patch works as intended.
Comment #2
justintime CreditAttribution: justintime commentedThanks for reviewing - committed to dev.
Comment #3
scroogie CreditAttribution: scroogie commented*edit*
I posted too early. Perhaps somethings not right with my install.
Somehow, in my installation, the "Image Sorting" display shows nodes in a different order than the 'Show all thumbnails' display, although both inherit the sorting from the default display. Can you reproduce that? I used the preview in the Views UI and compared the nids.
Comment #4
justintime CreditAttribution: justintime commentedI tried, and can't reproduce. Can you revert the view? Also, the live preview is kinda jenky at times, you might try using the "hidden" urls to test:
/gallery_grid/
/ng_sort/
Comment #5
scroogie CreditAttribution: scroogie commentedMhm, I still have the same problem, although I reinstalled ng. Did you try with a large amount of images?
Have a look at the demo page:
http://ng3demo.sysadminsjourney.com/node/1962/images
http://ng3demo.sysadminsjourney.com/ng_sort/1962
The first page shows nid 2449 first, the second lists 2007 first.
Comment #6
justintime CreditAttribution: justintime commentedThe demo site didn't have this fix yet :)
If you look at it now, they are in sync.
BTW: I had an older version of Drupal on that site, and was getting WSOD after upgrading. Seems st(), while recommended in the API docs, isn't present in older drupal versions. I'll be rolling that one back!
Comment #7
scroogie CreditAttribution: scroogie commentedAre they really in sync?
http://ng3demo.sysadminsjourney.com/node/1962
shows 1993 first.
http://ng3demo.sysadminsjourney.com/node/1962/images
shows 2429 first.
Comment #8
scroogie CreditAttribution: scroogie commentedIs this maybe a problem of the views cache? On my local install, I can't find any exact pattern in which this happens.
Comment #9
justintime CreditAttribution: justintime commentedI finally duplicated this. I created a new gallery, with a bunch of images. Everything was in sync, until I went to the manage images page, and clicked save. I got the warning about not being able to find the sort view, and from there on, the images on the manage images page were in a different order than the view and sort tabs.
Debugging...
Comment #10
justintime CreditAttribution: justintime commentedFound the cause of the error, but there's still a bug in there..
Comment #11
justintime CreditAttribution: justintime commentedHeh, I found it.
When you use plupload and/or devel generate to create a bunch of new images, depending on the speed of your server, you'll likely end up with multiple images created per second. In my case, I had groups of ~ 20 all created within the same second. While both manage images and view images differed on the order of nodes within groups, they always agreed that group A came before group B.
I'm going to commit the patch above since it's an obvious bug, but I think the easiest/best way to fix this is to add another sort on nid descending that will kick in when multiple images have the same weight and post date. Can you test this? If it works for you, I'll commit that in as default.
Comment #12
justintime CreditAttribution: justintime commentedMarking as need review.
Comment #13
scroogie CreditAttribution: scroogie commentedAh, that makes sense! The above fix is clear. Adding another nid descending sort to the default display of the image view fixed all sorting for me. If you commit the change, please remember the SQL fallback. :)
Comment #14
justintime CreditAttribution: justintime commentedCommitted to dev. FWIW, I just replaced the sort on the created date descending with nid descending, since sorting by nid implies date.
Also, something to think about. While we're in dev, it's not an issue because we're allowed to have some things need manual tweaking, but once we hit alpha and have a larger number of testers, we need to make a hook_update_N() for each change to views. Updating the default views file in the module doesn't do anything for existing installations until the admin "Revert"'s the view.