For managed file not added file usage
Migrated issue
Reported by: notifyone
Problem/motivation
Confirmed on 8.x-1.10. Files uploaded through a managed_file attribute are saved as temporary files. The module stores the file ID in the link options but never marks the file permanent or records file usage. Cron deletes the file after system.file:temporary_maximum_age (six hours by default), and the attribute points to a file that no longer exists.
Steps to reproduce
- Add an attribute with
type: managed_file. - Upload a file on a menu link and save.
- The file entity has status
0(temporary) and no entry infile_usage. - Run cron after the temporary age has passed: the file is gone.
Proposed resolution
In menu_link_attributes_menu_link_content_form_entity_builder(), or in a menu_link_content presave/delete hook, for every managed_file attribute:
- mark newly referenced files permanent and add usage with
file.usage(menu_link_attributes,menu_link_content, link ID); - remove usage for files no longer referenced, and for all files when the link is deleted.
Related issues
- #3365618 Allow to change upload formats for managed_file
- #3199793 (closed) Implement upload location for file uploads
Edited by Norman Kämper-Leymann