While testing for issue #1918762, I noticed that if I created multiple badges and set some to use an image from the library (previously uploaded for another badge), all file usage did not appear in the {file_usage} table. There was only one entry for the use of a given image file, no matter how many badges were using the image.
To replicate:
- create a badge and upload an image for it
- create a second badge and choose to use the image already in the library
- view the {file_usage} table in the database and note that there is only one usage entry for that file (fid in {file_managed})
Proposed resolution:
- file usage is tracked on a per-badge basis, so that if multiple badges are using the same image, it is tracked in the database
- file usage is added/removed when badge images are later swapped or edited
- file usage is removed when a badge is deleted
For the above, need to make certain that we can still see images in the library, even if no badges are using them at the moment. Need to look into how we get images to show on that tab. Grabbing this for myself at the moment, since I opened the can of worms...
Comment | File | Size | Author |
---|---|---|---|
#1 | user_badges-file-usage-1969668-0.patch | 10.32 KB | indyana |
Comments
Comment #1
indyana CreditAttribution: indyana commentedFinished working on this. It required several changes, including adding detected badge images to the database for tracking and adding/deleting file usage markers for individual badges. A more detailed summary is below. This should more accurately track the usage state of images. Previously, there were situations where an image in use could be deleted.
The patch is for the current 7.x-2.x-dev; I did no testing for other code bases. Please comment with results if you apply this patch.
Changes:
Comment #2
shabana.navas CreditAttribution: shabana.navas commentedThanks for the patch. These changes require more testing by other users. I have fixed a similar issue (https://drupal.org/node/1983978) where images could not be deleted. Now, you can delete an image that is no longer used by any badges and modules. Once other users have okayed this patch, I will go ahead and commit it asap.
Comment #3
shabana.navas CreditAttribution: shabana.navas commentedI have ported and committed the patch to the 7.x-3.x-dev version. Please test it out and give your feedback. Thanks @indyana for the patch. Great work!
Comment #4
shabana.navas CreditAttribution: shabana.navas commentedComment #5
jlandfried CreditAttribution: jlandfried commentedI'm no longer seeing the issue in the 7.x-3.x-dev version, so this looks good to me!
Comment #6
shabana.navas CreditAttribution: shabana.navas commentedGreat to hear! It will definitely find its way to the production version soon.
Comment #7
shabana.navas CreditAttribution: shabana.navas commentedHave added this to the production verison 7.x-2.0. Thanks for your work @indyana.