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.

CommentFileSizeAuthor
ng3-use-views-for-all.patch4.75 KBjustintime
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

scroogie’s picture

Status: Needs review » Reviewed & tested by the community

Ha, I just noticed this when testing out the navigator patch. Somehow the order switched around. Great catch. Patch works as intended.

justintime’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for reviewing - committed to dev.

scroogie’s picture

Status: Fixed » Needs work

*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.

justintime’s picture

I 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/

scroogie’s picture

Mhm, 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.

justintime’s picture

The 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!

scroogie’s picture

scroogie’s picture

Is this maybe a problem of the views cache? On my local install, I can't find any exact pattern in which this happens.

justintime’s picture

I 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...

justintime’s picture

Found the cause of the error, but there's still a bug in there..

Index: node_gallery.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/node_gallery/node_gallery.module,v
retrieving revision 1.18.2.121
diff -u -r1.18.2.121 node_gallery.module
--- node_gallery.module	17 Nov 2010 04:46:23 -0000	1.18.2.121
+++ node_gallery.module	18 Nov 2010 03:41:17 -0000
@@ -388,7 +388,7 @@
         }
         // If we change an image's publish status, clear the caches
         $publish_status_changed = FALSE;
-        $pos = node_gallery_get_image_position($image->gid, $image->nid);
+        $pos = node_gallery_get_image_position($node->gid, $node->nid);
         if ($node->status == 1) {
           // It should be in the cache, if not, clear them
           if (! isset($pos)) {
justintime’s picture

Heh, 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.

justintime’s picture

Status: Needs work » Needs review

Marking as need review.

scroogie’s picture

Status: Needs review » Reviewed & tested by the community

Ah, 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. :)

justintime’s picture

Status: Reviewed & tested by the community » Fixed

Committed 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.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.