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.
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.
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).
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.
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.
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).