I don’t know if this is related to the previous issue about sorting, ( http://drupal.org/node/471536) or if this is a problem with ImageField and not this module, but since there was a previous issue and patch for a related problem, I figured I’d start here first.

When I upload a zip of 14 sequentially named images (image01.jpg, image02.jpg etc), in the UI they appear to be in the correct order until I save the node. After the node is saved, the images are out of order in a weird way:

image11.jpg, image10.jpg, image14.jpg, image13.jpg, image12.jpg, image01.jpg, image02.jpg, image03.jpg, image04.jpg, image05.jpg, image06.jpg, image07.jpg, image08.jpg, image09.jpg

Maybe it’s just coincidence, but it seems like it’s ordering 01-09 correctly, but blowing up after 10 for some reason.

Just to test, I renamed the images with letters alphabetically. (a.jpg, b.jpg, c.jpg etc) Again, when I upload the zip file, the images are shown in the correct order in the UI, it is only after I save the node that they become out of order.

In this case, the order becomes: k.jpg, j.jpg, n.jpg, m.jpg, l.jpg, a.jpg, b.jpg, c.jpg, d.jpg, e.jpg, f.jpg, g.jpg, h.jpg, i.jpg

The images are in the same incorrect order as they were when the file names were numbered. This also happens in the exact same way with I use the HTML5 upload vs. a zip.

I'm on Drupal 6.22. Hopefully this description is useful. Thanks for the great module!

- Dan

CommentFileSizeAuthor
#15 imagefield_zip-order-1335630-15.patch1.43 KBosopolar
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikeytown2’s picture

Making sure things where in the right order was part of my QA pass. What version of CCK are you using?

ashcomd’s picture

I'm using CCK 6.x-2.9 and ImageField 6.x-3.10

- Dan

mikeytown2’s picture

Title: Incorrect sorting after save » Incorrect sorting after save (CCK 6.x-2.x)

hmmm, going to guess this is an issue with CCK 6.x-2.x. I'll see if I can get a test environment setup with CCK2 installed.

MJH’s picture

I have the same problem:

1) I upload the zip file and all images are shown in the correct order on the node-create/edit-form
2) After saving the node, the sort order is wrong (both in the published node and in the edit-form).
3) If I now reorder the images manually and save the node again, the correct order is saved and stays that way.

I use:
Drupal 6.22
PHP 5.3.3
CCK 6.x-2.9
ImageField 6.x-3.9
ImageField Zip/HTML5 Bulk Upload 6.x-1.2

marcus178’s picture

I'm seeing the same problem.

marcus178’s picture

I have found that if you reorder the 1st first image by moving it down then back before saving, they will save in the correct order.

pedromvpg’s picture

Same issue

pedromvpg’s picture

Also happening with CCK 6.x-3.0-alpha3

pedromvpg’s picture

Also happening with CCK 6.x-2.9

mikeytown2’s picture

Version info for what I'm using
CCK: 6.x-3.0-alpha3
FileField: 6.x-3.10

And from our internal wiki

Patches for CCK (all fixing notices):
http://drupal.org/node/1118792#comment-4358322 - array_keys() expects parameter 1 to be array, null given in content_multigroup.node_form.inc
http://drupal.org/node/1244534#comment-4845816 - Notice: Undefined index
http://drupal.org/node/1247732#comment-4857954 - Undefined index: _remove
http://drupal.org/node/1156096#comment-4868230 - Notice: Undefined index: title/description in content_storage()
http://drupal.org/node/1251146#comment-4871780 - Notice: Undefined index: #children in template_preprocess_content_field()
http://drupal.org/node/1251160#comment-4871816 - Notice: Undefined index: #field_info in fieldgroup_form_alter()
http://drupal.org/node/1265080#comment-4928778 - Notice: Undefined property: stdClass::$broken in content_handler_field->render()
http://drupal.org/node/1316510 - fix undefined index '#id' notice in form_alter hooks
http://drupal.org/node/533610#comment-5157454 - Notice: Undefined index: safe in theme_text_formatter_default()

Patches for FileField (mostly fixing notices):
http://drupal.org/node/1180508#comment-4872304 - Warning: array_merge() Argument #2 is not an array in filefield_widget()
http://drupal.org/node/1164892#comment-4500360 - Warning: Trying to get property of non-object in filefield_field_sanitize()
http://drupal.org/node/1317424#comment-5146998 - Notice: Undefined index: fid in filefield_widget_process
http://drupal.org/node/1415840#comment-5514392 - Fatal error: Cannot unset string offsets
http://drupal.org/node/1677208#comment-6213652 - Notice: Undefined index: data in theme_filefield_widget_preview

pedromvpg’s picture

Applied every patch and it still messes up the sorting after saving or after I upload extra images.
Is this not happening to you mikeytown2 ?

mikeytown2’s picture

Sorting is working for us. It's really hard for me to debug a problem I can't reproduce.

pedromvpg’s picture

Maybe we didn't explain what is happening exactly. It was a while before I noticed this was happening.
Here's what's happening:

When editing or creating a node, if you try uploading images using the Bulk upload field if it is more than, lets say 10 images, and they're file names are 1.jpg, 2.jpg, 3.jpg (...), once the upload process is complete every thing looks ok. Images look ordered by file names.

The issue occurs when, after saving, you go back to the node edit page and the images are reordered in what seems to be a random ordered: 9.jpg, 2.jpg, 6.jpg (...).

This does not happen with your installation?

Maybe I didn't apply one of those patches correctly but really... I don't know what else to do.

Would you consider providing us with the modules you're using to test those out?
I would assume it would be the CCK, FileField and ImageField Zip/HTML5 Bulk Upload modules.

Thanks for your troubleshooting.

lambrusco’s picture

I have the same problem, has anyone found a solution?

thanks

osopolar’s picture

Status: Active » Needs review
FileSize
1.43 KB

To reproduce the bug: upload 10 images at once and than click again the bulk-upload button with none or more images selected. The last image (the 10th) will now be the first one.

Debug: Add dpm($_POST[$field_name]); to the beginning of the function imagefield_zip_add_files_to_form() and after the second time submitting the bulk-upload you will see that the first image has the _weight 0, the second 1 and so on until the 9th with the weight 10. But the 11th and following images have the weight-10. Changing the order of the images before the second bulk-upload operation changes the weight in the $_POST-array and preserve the order as observed by marcus178 in #6.

In content_multiple_value_form() there are two more properties for $element['_weight']: #delta and #weight. I found that the problem disappears and the correct order is kept when I set $delta_element['_weight']['#delta'] = $delta in imagefield_zip_add_files_to_form().

There is another similar issue with the order: If you use bulk-upload to upload one or more images to a new node (node/add) without saving, then you will see first the two image-field widgets followed by the bulk-uploaded image(s). If you set one ore more images for bulk-upload but use node save this time to add the bulk-upload-images then the first or first two bulk-upload-images won't be added as expected after images uploaded before, instead they get position one (and two). The same effect you will see if you have an existing node with some images and delete one in the middle but do not save yet save the changes. Add one or more images to the bulk upload field and upload them by saving the node (not with the bulk upload button). The new image will be placed at the position of the deleted image.

This is caused by the way the delta is determined in imagefield_zip_page_submit(). The attached patch fixes this too.