file_move() does not update file_managed when replace = FILE_EXISTS_REPLACE (and the file does exist)

Created on 25 August 2017, about 7 years ago
Updated 1 February 2023, over 1 year ago

Drupal core does not make use of file_move. You'll need a custom (or contrib) module that makes use of it.

1) Upload a file to an entity that supports file attachments
2) Take note of the data in file_managed (the uri should be pointing to the default upload location)
3) Save the entity, triggering the custom / contrib module that makes use of file_move
4) Note that file_managed uri has been updated to the new location (regardless of whether the module is using FILE_EXISTS_RENAME or FILE_EXISTS_REPLACE)
5) Edit the entity and remove the file (there are no changes to file_managed at this point)
6) Upload the same file again (there is a new fid in the default location in file_managed)
7) Save the entity (triggering the same file_move process as before)
8a) Note that FILE_EXISTS_RENAME has updated file_managed uri to use the directory to which it has been moved and it uses the _0 version of the file name
8b) Note that FILE_EXISTS_REPLACE has not updated file_managed uri; it still points to the default directory to which Drupal initially uploads it
9a) Note that the file with the _0 version of the name does exist in the directory to which it was moved (and no longer exists in the default directory to which it had been uploaded initially)
9b) Note that the file with its original name does exist in the directory to which it was moved (and no longer exists in the default directory to which it had been uploaded initially)

Final note: Whether you upload the same file or an updated version of the file, FILE_EXISTS_REPLACE fails to update the uri in file_managed but does actually move it to the correct location and replaces the existing file.

πŸ› Bug report
Status

Closed: works as designed

Version

9.5

Component
File systemΒ  β†’

Last updated 1 day ago

Created by

πŸ‡ΊπŸ‡ΈUnited States vegantriathlete Lakewood, CO

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡³πŸ‡ΏNew Zealand quietone New Zealand

    There has been no activity here for 5 years, until 9 months ago when a maintainer asked for sample code to reproduce this. This is also about a now deprecated function.

    Since we need more information to work on this and none has been provided, I am closing this issue.

Production build 0.71.5 2024