The core image module isn't flushing Image derivatives correctly when a file is moved via file_move(), it's using the $file->uri instead of $source->uri, or in other words it's using the new file URI instead of the original/source file URI and therefore there are no Image derivatives to be flushed.
Basic reproduction steps
- Create a new Article node with an Image attached.
- View the new Article ensuring that an Image derivative is successfully generated.
- Programatically relocate the uploaded image using
file_move(). - Confirm that original Image derivatives are still present in file system.
- Apply patch and repeat 1-3.
- Confirm that original Image derivatives from last step are no longer present.
Original issue:
FileField misses step #7.
1. User uploads an image that is placed in the public folder.
2. Imagecache creates a thumbnail image and places it in the styles/thumbnail/public folder
3. The thumbnail image is sent to the node by ajax.
4. The node is saved.
5. FileField does its magic creating an aliased name and folder, deleting the image in the public file root folder.
6. The node is viewed so a large imagecache image is created with the aliased name and folder.
7. ****[The original thumbnail needs to be deleted now since it isn't needed anymore]****
8. The node is edited and another thumbnail is created with the correct alias and path while the original thumbnail image sits unneeded in the imagecache thumbnail public folder waiting to be deleted.
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | drupal-image_file_move-1159258-18.patch | 2.13 KB | deciphered |
| #18 | interdiff.txt | 1.99 KB | deciphered |
| #16 | drupal-image_file_move-1159258-16.patch | 2.07 KB | deciphered |
| #14 | drupal-image_file_move-1159258-14.patch | 1.65 KB | deciphered |
| #9 | hook_file_move-1159258-9.patch | 432 bytes | deciphered |
Comments
Comment #1
Tim Jones Toronto commentedI have the same problem here when editing a node and deleting the node image.
When adding a file image, the thumbnail filename is not being created using the Filefield Paths name – it keeps the original filename.
When you then edit that node, the imagecache system creates another image with the Filefield Paths filename. This adds a second file with the correct Filefield Paths name.
If you then delete the file, it only deletes the Filefield Paths image name and not the orphan image that has the original filename.
To see more clearly, simply watch the folder “thumbnails/public/YOURPATH” when content is being uploaded/deleted.
Cheers
Comment #2
h0tw1r3 commentedIs this still a bug in 7.4? I seem to remember looking at this briefly with D7.2, but now that I'm trying to reproduce under D7.4 it's working as expected.
Comment #3
Tim Jones Toronto commentedHi,
Re-tested with Drupal 7.7 and latest FFP Dev on another hosting system to be sure. The thumbnail is still being kept (even by simply editing the node and removing the file image):
e.g. files/styles/thumbnail/public <--- the 'removed' file is still in this folder after deletion (as per #1 point 7).
** after more testing...
It seems the problem goes away if you specify the folder path BEFORE enabling FFP in the image field setting. Then when enabling FFP specify the file path again and should work ok. There appears to be two fields being used for file paths (?), so both must be set. If you do not specify one before enabling the FFP you will get files left over as I experienced in the post above. The two MUST be at least set and in sync.
Cheers.
Tim
Comment #4
amateescu commentedMarking as fixed.
Comment #5
Tim Jones Toronto commentedI have re-tested with new site using latest dev and Drupal 7.8. The problem is now returned despite what i wrote in #3.
The thumbnail filename is not being created using the Filefield Paths name – it keeps the original filename.
The image is being renamed as e.g. [node:title]_[node:nid].[file:ffp-extension-original] fine.
But in the folder files\styles\thumbnail\public\images it has the original filename set and this file was not renamed.
I am using: 'images' as the 'File path' name.
Comment #6
decipheredI don't know if FileField Paths should be expected to delete an unnecessary Image Style image, given that FileField Paths is invoking
file_move()I would assume that the Image module should be implementinghook_file_move()to handle the deletion of any moved and unnecessary cached Image Style images.Moving to Drupal Core for the time being.
Comment #7
Tim Jones Toronto commented@#6 The thumbnail filename is not being created using the Filefield Paths name. For me, this was the problem – on creation (it keeps the original filename), which i think is later causing the problem of non-deletion (maybe trying to be deleted with the updated name?). The filenames have become confused.
Also looking at #3: "There appears to be two fields being used for file paths (?)" .. this would be useful to understand as there are two paths in the DB being kept for the single file source?
Thanks!
Comment #8
decipheredTim,
The file is not renamed until you save the node/entity, as the node/entity specific tokens can't be known until you have saved it, therefore when the thumbnail is first created it uses the filename that it is aware of, which is the unprocessed filename. Once you save the node/entity the original file is processed and moved via
file_move(), which triggers implementations ofhook_file_move()which should be used by the Image module to to handle and no longer useful cached Image Style images.That is what the core issue is here and once/if that is resolved the issues you are having with FileField Paths will be resolved.
Cheers,
Deciphered.
Comment #9
decipheredLooked into the Image module and it appears to be flushing all Image derivatives of the
$file->uri, which is the new location, instead it should be flush derivatives of$source->uri.Confusion likely comes from the fact that
file_move()takes the arguments in the order of 'old', 'new', whereashook_file_move()uses the reverse order.Comment #9.0
decipheredUpdated issue summary.
Comment #10
quicksketchAt first glance it looks like @Deciphered is correct here. As usual, this would probably benefit from a test though :\
Comment #11
Tim Jones Toronto commented>The file is not renamed until you save the node/entity..
Yes, agreed. This was my point #1 - I had to save the node in order to edit it, which is where I noticed the problem.
Can do testing on this and report back.
Cheers for now,
Tim.
Comment #12
Tim Jones Toronto commented@Deciphered - have tested #9 and confirmed it works: It moves the original filename to new filename with new folder path as expected.
Re-tested #9 patch on core without Filefield Paths module enabled and verified everything working as expected.
Thanks for looking at this. Will be testing this on another system this week to double check etc.
Cheers! Tim
Comment #13
decipheredJust a quick update, due to the drastic changes in D8 with the new /core directory my Aegir based development environment no longer allows me to dev on D8 so therefore I have not yet been able to write the tests.
I hope to get this resolved ASAP or atleast resort to a temporary dev environment, but I have not yet had time to do so.
Cheers,
Deciphered.
Comment #14
decipheredAdded test to fail and prove need for patch at comment #9.
Comment #16
decipheredPatch with Test and Fix.
Comment #17
decipheredForgot to mark as 'Needs Review'
Comment #18
decipheredUpdated patch after IRC review by XJM.
Comment #19
xjmLooks great now, thanks @Deciphered!
Comment #20
dries commentedCommitted to 8.x and backported to 7.x. Thanks.
Comment #21.0
(not verified) commentedUpdated issue summary.