Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Now that file_entity_revisions is actually revisioning the file, it would be a good thing if it preserved the filename.
Let's say I have a file entity with the file URI of cat.png
I go to make a new revision of this file and upload dog.png
Right now, the new file will be cat_1.png because it is using the original URI as the base.
This patch will do its best to preserve the uploaded filename for new revisions. Due to file_entity processes it will actually be dog_1.png but that's still better than calling it cat_1.png when it's a dog.
Patch forthcoming.
Comments
Comment #1
merlinofchaos CreditAttribution: merlinofchaos commentedComment #2
Fabianx CreditAttribution: Fabianx commented**RTBC** - And its raining cats and dogs! - But the right one for each revision!
Comment #3
seanBWorks great! Thnx..
Comment #4
pcrats33 CreditAttribution: pcrats33 commentedI personally would rather see it saved as cat.png. What if there is a link on the website to the file, suddenly the link is broken? Not saying not to fix it, but not taking it in a different direction from how drupal core normally handles file replacements.
Comment #5
Fabianx CreditAttribution: Fabianx commented#4: But the name is and cannot be preserved (its called cat_1, cat_2, cat_3 already).
What you want is permanent image uri's, but that is a different story.
With revisions you do not want the dog to be suddenly on the live page, because it overwrote the cat ...
This is for modules like workbench or CPS.
Comment #6
pcrats33 CreditAttribution: pcrats33 commentedI just wrote a patch that preserves the original name forever, and stashes revisions as _2, _3, etc. I will share once I figure out how to format patches on here. It works very well and you can also revert and still not lose the filename. The idea is in large websites people may want to replace a form, but they don't want to update the links to those form. If the filename changes, the link breaks. If you want to replace cat with dog, delete cat and upload dog as a separate file. That's my intent anyways, and that's how Drupal does it with file edit/replace.
Comment #7
das-peter CreditAttribution: das-peter commented@pcrats33 Sounds great. Regarding patches you might want to check this page: https://www.drupal.org/node/707484
Comment #8
pcrats33 CreditAttribution: pcrats33 commentedOk here is the patch.. This makes it so the original filename for a file stays that way as long as you are replacing the file. Also I was originally working on a patched version from https://www.drupal.org/files/issues/files_ought_to_have_a-2097975-14.patch which I highly recommend be included in a new version of this module. If you applied this patch as I did, you will also need to add a couple lines to the file_entity_revisions.pages.inc file:
function file_entity_revision_revert_confirm_submit() : around line 128.
Comment #9
Kenneth Lancaster CreditAttribution: Kenneth Lancaster commented...and it works as designed. Perfect. Thanks!
Comment #10
pcrats33 CreditAttribution: pcrats33 commentedI'm updating the patch, I found an error in functionality - when editing a file but not changing the file, it tries to replace the file with itself, but file_unmanaged_copy returns a FALSE in this instance, and the file->uri is replaced with the false value. This new patch handles that case so that the file URI isn't lost.
Comment #11
Fabianx CreditAttribution: Fabianx commentedComment #12
Charles BelovHere is another use case.
We are having a similar issue where cat January 2015.pdf is the old version and cat February 2015.pdf is the new version.
What we would want to happen is the new file retains the new name cat February 2015.pdf and the old name redirects to the new name.
So, maybe this is a configuration option in the module?
Comment #13
Charles BelovSorry, I see this is covered in comment #5. Sort of.
The problem is, if the original file name has the date in the name, then we don't want to keep the original file name, as it will give a wrong impression. We would only be okay keeping the old file name if it had no misleading content.
It is fairly common in our organization to use dated file names, so we would not want to keep the same file name, we would want the redirect to the new name instead.
Comment #14
Kenneth Lancaster CreditAttribution: Kenneth Lancaster as a volunteer commented@Charles Belov, you are correct in your last comment of "we don't want to keep the original file name" if it contains some kind of date. It would be better to have the first file, or you could change the file name, to something more generic with no date in it. Then when you upload a new file, in your example with a date in it, that file will replace the original file. However, the URL will stay the same and the way we have it set up now, both versions are retained on the server so you can always revert back to an older file too.
Comment #15
Charles BelovRealistically, nobody on our staff is going to go in and genericize the file name. And we don't want to retain the out-of-date file, unless the file name is changed in some way, because Google has likely indexed the old file and we don't want to serve the old file. What we really want is to serve the new file regardless of whether the old or new file name is used.
However, Workbench Moderation revisions prevent the old file from being deleted in IMCE. So a rename of the old file would be better.
Comment #16
Charles BelovI guess the bottom line is that this would best be a configuration option, not a do always.