From d46ce35dcf4a740d637e5878ec995a07ec92ae73 Mon Sep 17 00:00:00 2001
From: Andrew Berry <deviantintegral@gmail.com>
Date: Wed, 30 May 2012 15:42:04 -0400
Subject: [PATCH] Issue #1608916: Always add a weight to uploaded images.

---
 node_gallery.module |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/node_gallery.module b/node_gallery.module
index 6face64..cb396bc 100755
--- a/node_gallery.module
+++ b/node_gallery.module
@@ -561,6 +561,11 @@ function node_gallery_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
       break;
     case 'insert':
       if (in_array($node->type, (array)node_gallery_get_types('image'))) {
+        // Always add new images to the end of a gallery. Otherwise, when
+        // adding new images, they might be inserted somewhere in the middle of
+        // the gallery if the order has been customized.
+        $node->new_weight = db_result(db_query("SELECT MAX(weight) FROM {node_gallery_images} WHERE gid = %d", $node->gid)) + 1;
+
         node_gallery_set_gallery_cover_image($node);
         node_gallery_set_image_weight($node);
         node_gallery_clear_gallery_caches($node->gid);
-- 
1.7.10.3

