craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.22k stars 625 forks source link

[5.x]: files being deleted from volume upon interaction before completion of image transforms #15380

Closed fvwanja closed 1 month ago

fvwanja commented 1 month ago

What happened?

Description

Files that I upload go into the directory "uploads". All resized versions of the original go into "uploads/resized"

Base URL = /uploads (pointing to https://example.com/uploads) Base Path = /path-to/uploads (absolute path is different on each server/environment)

No custom image transforms were created. All image transforms are generated by the system.

Does work Uploading files directy via Assets (/admin/assets) always works as expected. The original file and the resized versions exist.

Does not work When editing any Entry Type within an entry, uploading a large file and interacting with the associated entry (for example changing the title or the alt-text of the image) while any image transforms are still being applied, can lead to the deletion of the original image.

Steps to reproduce

  1. Edit any entry
  2. Edit any Entry Type within
  3. Upload a large image and directly edit the image (/admin/assets/edit/slug) entry by changing the title or any other data and hit save. This step has be finished, before the image transforms are completed
  4. The original image is removed from the file system

We got the same results with different image files and on different servers (offline/local and online).

Expected behavior

The original file should never be deleted from the server.

Actual behavior

The original file is actually deleted from the server. Why does this happen? There must be an unlink or something similar somewhere in the core code of Craft 5.

Video

https://github.com/user-attachments/assets/18d2b080-087a-406d-993a-4eabec3314cb

00:00 Uploading a file directly to Assets works as expected 00:21 ✅ The original file can be accessed in the browser 00:26 Go to entries 00:30 Edit any entry 00:31 Edit any Entry Type („Block: Media Test ABC”) 00:33 Upload small file „alex” 399 KB 00:46 On the right side of the screen we see the uploads directory in the Finder with the new file „alex”. Image transforms are being generated (what we can also see in the Finder) 00:55 ✅ The original file „alex” can be accessed in the browser 01:02 Upload large file „edward” 3,5 MB 01:17 On the right side of the screen we see the uploads directory in the Finder with the new file „edward”. Image transforms are being generated (what we can also see in the Finder) 01:18 Edit „edward”, change a value, hit „Save” 01:22 Bottom left on the screen we see the have the first occurence of an image transform, that is not yet finished (which is okay at this point, because we were just too fast) 01:23 ❌ The image file „edward” is being deleted (see Finder right side). At the same time the image transform _285x190_crop_center-center_none is generated 01:39 Upload another smaller file „prince” 2,6 MB 01:58 ✅ On the right side of the screen we see the uploads directory in the Finder with the new file „prince”. Image transforms are being generated (what we can also see in the Finder) 02:02 After editing the same data as previously done with „edward”, the image still exists, because the image transforms are already completed 02:17 Second try with „edward” 02:30 ❌ After editing and hitting „Save”, the image "edward" is deleted


Thank you very much for your time and effort! If you need any further information, I will provide what I can!

👍

Craft CMS version

5.2.1

PHP version

8.3.8

Operating system and version

Linux 6.5.0-18-generic

Database type and version

MariaDB 10.6.18

Image driver and version

Imagick 3.7.0 (ImageMagick 6.9.11-60)

Installed plugins and versions

brandonkelly commented 1 month ago

Can you post a screenshot of your volume’s settings?

fvwanja commented 1 month ago

Hey @brandonkelly, sure thing!

Screenshot 2024-07-25 at 16 00 05

Variables:

And just for the records, this is the file structure:

Screenshot 2024-07-25 at 16 04 09

If you need anything else, please let me know 🙏

brandonkelly commented 1 month ago

That’s the filesystem, I’m asking for the volume’s settings.

fvwanja commented 1 month ago

Sorry my bad!

Screenshot 2024-07-26 at 13 10 25

We also have a second volume set up

Screenshot 2024-07-26 at 13 12 11

angrybrad commented 1 month ago

@fvwanja I think I followed the steps in your video as closely as possible (but I had to make a few assumptions). Regardless, I'm not able to reproduce.

Is there any chance you can send over a database dump and your composer.json files to support@craftcms.com so we can dig in further?

fvwanja commented 1 month ago

I changed the value of fs in config/project/volumes/uploads--xxxx.yaml

from fs: uploads

to fs: $BASE_PATH

I made a screenshot-comparison of the filesystem changes that I made. We are currently testing these changes on different environments to confirm that they do not produce the same error with the other filesystem. I will let you know, as soon as we can confirm that the issue is solved.

However I cannot say or guess, what happened here. I will still send you the dump and composer.json file of the broken version.

filesystem-changes

fvwanja commented 1 month ago

So we can confirm, the issue no longer occurs after changing the value $BASE_PATH. I do not understand what this does, and why it matters, since the outcome is the same...

If you find out what it was, feel free to let me know.

Thank you for your time and effort!

<3