dmitrybubyakin / nova-medialibrary-field

Laravel Nova field for managing the Spatie media library
MIT License
262 stars 62 forks source link

Filtering unused media … or … detached media is not deleted #103

Open JonathanDoelan opened 3 years ago

JonathanDoelan commented 3 years ago

When adding media to a NEW resource, the media is first uploaded via JS and is related to a TransientModel. After submitting the whole form, the media is moved from the TransientModel to the newly created resource model. In case of updating a resource, newly added media is NOT related to a TransientModel, but to the already existing resource model.

  1. BUT … for example if we’re editing a news article, which is published online on the front-end, and adding a new media file, it is online before we’ll submit the whole form. This also means that maybe a file or an image is public, that the editor does not want to be published.

  2. AND … if we’re using Whitecube\NovaFlexibleContent and we choose a layout where we can add media files, and then delete the NovaFlexibleContent-Layout, the layout is gone, BUT the media is not deleted! The same happens if we add a new Flexible-Layout and attach new media files, but than we don’t submit the form: The media is attached but the layout isn’t.

The problem is that on the DB table it looks like the media is correctly attached, but it isn’t. So we have no chance to filter unused files.

Solution/suggestion: Every newly added media file should be linked to a TransientModel, including on UPDATE-form. And only if the from is submitted the media is moved from the TransientModel to the resource model.

If so, then it would be easy to filter all files that are not actually related to any resource (in order to clean up).