Posted by tsvenson on April 28, 2009 at 9:57pm
Jump to:
| Project: | File (Field) Paths |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | postponed (maintainer needs more info) |
Issue Summary
I have a content type where authors can upload unlimited images using imagefield.
The problem is that when editing a node, the first image is used as the thumbnail for the first two uploaded images. When viewing the node the correct image is shown.
As this happens for every node of this content type I can only assume it is a bug.
Is there a way I can regenerate the thumbnail previews for existing content?
Comments
#1
I can't reproduce this problem. Uploading two images into the same multi-value field produces two separate thumbnails as you would expect. Could you provide the following?
- A list of all the configuration options you have set for your image field
- A screenshot of the problem occuring
- After uploading, use Firebug to inspect the thumbnail images, and report what the "src" path is for the thumbnails.
#2
The only special config I have is that the image file names are renamed using [title].[filefield-extension]. plu using Convert to lower case and Transliterate to clean up the file names.
I had a look in the thumbnail directory and I found that there where a few odd things. basically there where several dupes.
It should look like:
[title].jpg
[title]_0.jpg
[title]_1.jpg
[title]_2.jpg
[title]_3.jpg
[title]_4.jpg
These where also the sources in the edit view using Firebug.
But was instead:
[title].jpg - image 1
[title]_0.jpg - dupe of [title].jpg
[title]_0_0.jpg - image 2
[title]_1.jpg - image 3
[title]_1_0.jpg - dupe of image 3
[title]_2.jpg - image 4
[title]_2_0.jpg - dupe of image 4
[title]_3.jpg - image 4
[title]_3_0.jpg - dupe of image 4
[title]_4.jpg - image 5
[title]_4_0.jpg - dupe of image 5
So image 2 was never shown in the edit, but on the view.
When I deleted the existing thumbnails they where correctly generated.
I also added a new node on this content type and the same thing happened again. When I click the upload for each image it is previewed correct, but after saving the new node and then going back to edit it the first two are wrong. All images where added during the initial creation of this node.
I tend to think it is to do with that I rename the images and then let Drupal add the _[number] that screws this up. This only happens for the imagefield thumbnails. The original images are renamed and uploaded correct.
#3
Ahh, okay. I'm moving this to the FileField Paths module, since you're using node-level tokens it provides. Perhaps FileField Paths should make sure to delete the temporary thumbnail files after the original file has been renamed. Since what's happening now is the [title].jpg file will remain on the server forever, making any new uploads in that field conflict with the existing thumbnail.
@Deciphered, let me know if changes to FileField could make this easier.
#4
Thanks quicksketch,
Will look into this issue and see what I can determine.
Cheers,
Deciphered.
#5
Hi edde42,
I have confirmed the issue and have a simple fix for it.
Change line #598 of filefield_paths.module from:
file_move($thumnail_source, imagefield_file_admin_thumb_path($file['field']), FILE_EXISTS_RENAME);to:
file_delete($thumnail_source);@quicksketch
I believe the issue is that FileField or ImageField is constantly checking if it's thumbnails exist, and trying to recreate them if they don't?
FileField Paths was simply moving and renaming them based on the new filename, but then FileField/ImageField was also recreating them on top of that.
The fix above simply deletes the old ones and lets FileField/ImageField do it's thing.
Just curious on your thoughts on the behavior, if the re-creating of the thumbnails is something that you specifically changed at any stage?
Will likely commit the above fix in the next hour or so.
Cheers,
Deciphered.
P.S. Someone really needs to make functionality for D.o. to link @username to profiles and track mentions similar to Twitter.
#6
Thanks for a quick fix Deciphered, your a star.
Just to confirm (I am using the dev version) and I assume you mean line 588 and not 598?
#7
Hi edde42,
I probably do mean that line number, yes. The version I tested on is an internal build which obviously offset the exact location :)
Cheers,
Deciphered.
#8
Yes I specifically changed this behavior when I moved all the thumbnails from being called [filename].thumb.jpg to all living in imagefield_admin_thumbs/[filepath]. The previous approach was dependent upon hook_file_insert(), which I didn't like because it wouldn't work when files were re-used (say by the FileField Sources module) and it created thumbnails for ALL image files, even ones that had nothing to do with ImageField. Generating on-demand was a much easier solution and I plan to keep it that way unless it causes some new problem (no reports yet though). I think the solution you've suggested is just fine.
#9
Hi Deciphered,
Just want to let you know that your did not work very well, instead it created several new problems.
When creating a new node and uploading images it uses old thumbnails, if they exist, as preview after uploading (before saving the node).
Worse though is that images lose the [title] part, only the extension + _x for additional images are used. Not even the . (which I guess Transliteration might filter). This goes both for the thumbnail directory and where the original images are stored.
#10
Hi edde42,
Will have another look at it and see what I can find.
Out of curiosity, what version of FileField, FileField Paths and ImageField are you using?
If they are dev releases, the date would be handy to.
#11
Using the following:
FileField 6.x-3.0
FileField Paths 6.x-1.x-dev (2009-Apr-20)
ImageField 6.x-3.0
Also:
ImageField Tokens 6.x-1.x-dev (2009-Apr-27)
Needed that to be able to automatically generate alt/title for the images and that required the dev of filefield path as you know.
#12
Hi edde42,
Sorry I took so long to reply, I re-tested the issue and can not confirm the issue.
It seems highly unlikely that the change I made could have those particular side-effects. All it's doing is deleting the original, unprocessed thumbnails. It is ImageField that is creating the new thumbnails.
If possible can you test on a fresh install and post a step-by-step guide on how to reproduce the issue, making sure to note any relevant configuration options.
Cheers,
Deciphered.
#13
Hi Deciphered,
Took long to reply, your joking right? I can't complain as it took less than 17h mate :)
Problem is this site is rather critical to get ready asap. Unfortunately I don't really have time to set up a fresh test site, but I will see if I can find any more info for you while I work on it.
Also, this content type are using a whole bunch of modules, including workflow, workflow fields and content profile. I have some issues with workflow fields while creating new nodes, see issue #444112: User cant create their Content Profile for more info, that might cause this problem as well.
Here is a list of all modules I have installed on this site, maybe that can help you:
Drupal 6.10
Administration menu 6.x-1.x-dev (2009-Apr-27)
Advanced help 6.x-1.2
Backup and Migrate 6.x-1.2
Better Formats 6.x-1.0
Browscap 6.x-1.0
CAPTCHA 6.x-1.0-rc2
CCK Teaser Field 6.x-1.0-beta1
Checkbox Validate 6.x-1.1
Site Configuration Permissions 6.x-1.0
Content Construction Kit (CCK) 6.x-2.2
Content Profile 6.x-1.0-beta3
Content Taxonomy 6.x-1.0-beta6
Devel 6.x-1.16
Diff 6.x-2.0
Email Field 6.x-1.1
Email Change Confirmation 6.x-1.2
Frequently Asked Questions 6.x-1.8
FileField 6.x-3.0
FileField Paths 6.x-1.x-dev (2009-Apr-20)
Format Number API 6.x-1.4
Formatted Number CCK 6.x-1.1
Front Page 6.x-1.2
Global Redirect 6.x-1.2
ImageAPI 6.x-1.6
ImageCache 6.x-2.0-beta9
ImageField 6.x-3.0
ImageField Tokens 6.x-1.x-dev (2009-Apr-27)
LoginToboggan 6.x-1.4
Matrix Field 6.x-2.x-dev (2009-Apr-27)
Multiselect 6.x-1.3
Meta tags 6.x-1.0
Meta Tags by Path 6.x-1.0
Pathauto 6.x-1.1
Rules 6.x-1.0-rc1
Scheduler 6.x-1.3
SimpleViews 6.x-1.0
Statistics Advanced Settings 6.x-1.4
Submitted By 6.x-1.2
Taxonomy hide 6.x-1.02
Taxonomy Manager 6.x-1.0-beta2
Terms of Use 6.x-1.10
Token 6.x-1.11
Transliteration 6.x-2.0
Views 6.x-2.5
Webform 6.x-2.6
Workflow 6.x-1.1
Workflow Fields 6.x-1.1
Wysiwyg API 6.x-1.1
As you can see there are quite a few modules that are used for this content type as it has a workflow and also using several extra CCK fields, plus your modules to use tokens for the images to rename and also create alt/title texts.
If you look at the above issue for workflow fields I have submitted a list of php warnings I get, the imagefield is at the bottom in the list and there is one pathauto warning when saving a new node of this content type:
* warning: mb_eregi_replace() expects parameter 3 to be string, array given in [path]/sites/all/modules/pathauto/pathauto.inc on line 184.
which I assume must have something to do with the imagefield.
When I am done with this site I will see if I can reproduce it in a clean install. Right now I have been on 24/7 on this for a few weeks...
#14
Hi Edde42,
It could definitely be a tricky issue to track down with so many modules running.
I guess one thing to do would be the following:
- Create a node without my above fix, check and report behavior.
- Create a node with my above fix, check and report behavior.
- Comment out the line from the fix, create a node, check and report behavior.
Be sure to make each node as similar to each other and it should hopefully confirm whether the extra issue are related to the fix.
As for your other issue you linked to and the error you posted in your last comment; I ran into very similar issues on one of my testing servers, the issue appeared to be related to Pathauto and PHP 5.2.5. Try migrating your site onto another test environment (LAMP, XAMMP, MAMP, etc) and see if they still exist. While I won't go to deep into the issue, it's something that I never thought of at the time.
Let me know how you go.
Cheers,
Deciphered.
#15
As soon as I get a few h of zZzZz's (5am here) so I can focus better when I do the test.
One Q, do you mean that I should run without any of the two lines in the third test?
As I am using content profile I will have to create three users, but I will create each node exactly the same, with the same content and images for all cases.
Re Pathouto/PHP5.2.5, I just checked the phpinfo() in devel and it says the server the site is is using php5.2.4.
#16
Yup, either comment it out (Insert '//' before the line) or delete it completely.
#17
Above fix (#5) has been committed to DRUPAL-6--1.
Will keep issue open in the case that the other issues are related to the fix, but have not seen any evidence of this as of yet.
Cheers,
Deciphered.
#18
Hi Deciphered,
Sorry for the delay, a few things got in between. Here is the result from my tests. I did it like this (all as UID 1):
1 - Created 3 test users.
2 - Created the users content profiles with the exact same content in fields Except I used three sets of 5 images so that I could see if difference in the thumbnails etc...
3 - Edited the node to update the missing title etc as described in #444112: User cant create their Content Profile comment #3.
I also flushed all caches between each test.
When adding the images to the unlimited imagefield I browsed the first image for the first field, then clicked on Add another item, I did *not* click the upload button until the last, 5th, image had been uploaded.
With Workflow Fields Enabled
Please remember that files are named wrong here due to workflow fields and that title can not be edited before the node exists.
Test 1 - No code modification
When creating
Using old thumbnail previews.
No thumbnails are created in files/...
After Saved
Thumbnails are created, first two dupes in edit, and named as described in #3, but named only with the extension due to the workflow fields problem.
Due to the title problem alt/title are named "array [the rest is correct]" and no images are viewed
After Edit
Images are now viewed, but the files are not renamed.
Test 2 - Code modification
When creating
Using the same previews as for test 1.
After Saved
Files created correct and viewed properly in edit.
After Edit
Same
Test 3 - Line completely deleted
When creating
Using the same previews as for test 1.
After Saved
Files created correct and viewed properly in edit.
After Edit
Same
With Workflow Fields Disabled
Disabled Workflow Fields and cleaned up all image folders
Also I didn't need to edit the nodes as they where correctly created.
Test 1 - No code modification
Same except that files now named with correct title.
Test 2 - Code modification
Same except that files now named with correct title.
Test 3 - Line completely deleted
Same except that files now named with correct title.
Test 2 in IE8
Wrong images shown in preview.
Right images shown in edit and stored on server, but viewing the page showed wrong images. These where not even the same as had been used in preview when adding the node. Tried clearing IE's temporary folder and refresh the page. Same problem in FF3.0.10. I had to flush imagecache's cached images to get the correct images to show.
OK, phew, that took some time :)
My "Conclusion"
We can at least rule out Workflow Fields as it was the same result both with and without it.
In both test 2 and 3 the correct thumbnail images where created.
Since I have reused the titles for these nodes, that are used to rename the images, I believe this all boils down to a caching problem in Drupal. Could it be that when images are uploaded the code does not check if it already exist cached thumbnails or imagecache files with the same names? Then when the images are viewed there is not a proper check to see if the existing cache image is based on the original image or not? A simple timestamp check should be enough to know if the cached image needs to be regenerated or not.
How is the preview thumbnails generated when creating a new node? It seems they might not be properly deleted after the page is created.