Hello,

Lets imagine I have a file called a.pdf and I edit it by uploading b.pdf.
Should the final file on the server be name a.pdf or b.pdf? Instinctively I think the normal behavior is to remove a.pdf and place b.pdf on the server.

However, it is simply renames b.pdf to a.pdf and overrides the original file.
The addition of the "Keep original filename" button only adds to the confusion because, either way the final final will always have the name of the initial file.

The problem seems to be on line 838 of file_entity.pages.inc where, if the extension is the same, it simply file_unmanaged_copies to the original file path.
I've forced this if to always be false solving what I really think to be a bug.

You can test this behavior using https://simplytest.me.

Additionally, I think a redirect should be created from a.pdf to b.pdf after the file is changed. I didnt by using hook_file_update on a separate module.

Comments

raramente created an issue. See original summary.

joseph.olstad’s picture

Are you selecting the option 'keep the same filename' ?

#2958574: Enforce stricter "Keep Original Filename" option for same extensions

jdearie’s picture

I seem to be having the same issue.

I have a file titled a.pdf
I replace it with a file title b.pdf

The filename is overwritten as a.pdf but is the new b.pdf content

The same action occurs whether I check the Keep Original Filename box or not.

I also tried using the patch at https://www.drupal.org/project/file_entity/issues/2958574, but it seems to be fixing what I'm hoping happens - meaning I want the filename to be changed to the filename of the newly uploaded file UNLESS the Keep Original Filename box is checked.

I'm on 7.x-2.21

joseph.olstad’s picture

Status: Active » Closed (duplicate)
Parent issue: » #2958574: Enforce stricter "Keep Original Filename" option for same extensions

Hi jdearie, thanks for reporting. I believe there is an existing patch that will resolve this.
please try this RTBC patch #2958574: Enforce stricter "Keep Original Filename" option for same extensions
https://www.drupal.org/files/issues/2018-04-04/Change_filename_when_repl...
if it works for you, please report your findings in 2958574.

Your feedback is valuable and will help greatly for the next release.

joseph.olstad’s picture

Category: Bug report » Support request
Status: Closed (duplicate) » Needs review

actually, I'll leave this open as a support request until confirmation of results.

jdearie’s picture

installed the patch and it worked for me!

I uploaded a PDF (a.pdf) into Content > Files. Then edited its entity, and under "Replace file", uploaded a different file named "b.pdf", checked "Keep original filename", select the file, and saved. It saved as "a,pdf" but had the contents of "b.pdf".

If I unchecked "Keep original filename", when uploading it had "b.pdf" as the filename.

One thing to note - if your users don't change the Name field of the file entity (when using the media browser from WYSIWYG to upload a file), then the file entity name may still show the old file name but will still correctly link to the new file name.

cross posted results in 2958574

thx!!

joseph.olstad’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.