Add stored_filename attribute for downloadable files (#3670)

* Add `stored_filename` for downloadable files

* Remove orphaned stored files when a new downloadable file is uploaded

When uploading a new product file or directly replacing a service's file,
the old stored_filename was left on disk indefinitely.

- Add isStoredFilenameReferenced() to check whether a stored filename is
  still referenced by any product config, order config, or
  service_downloadable row before deleting.
- Add removeStoredFileIfOrphaned() that deletes the physical file only when
  no references remain (protects against the patch65 migration scenario
  where one stored_filename may be shared by multiple sibling records).
- In uploadProductFile(), capture the old stored filename before saving the
  new config and remove it after all records are updated.
- In updateProductFile(), capture the old stored filename when a new file
  is directly uploaded for a service/order and remove it after all records
  are updated.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
Adam Daleyandcopilot-swe-agent[bot] authored and GitHub committed 2026-05-30 13:26:13 +01:00
1 parent 05b3395c2b
commit bb1f7079e9
5 files changed
+332 -28

No files matched your search

+1
View File
@@ -938,6 +938,7 @@ CREATE TABLE `service_downloadable` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`client_id` bigint(20) DEFAULT NULL,
`filename` varchar(100) DEFAULT NULL,
`stored_filename` varchar(100) DEFAULT NULL,
`downloads` int(11) DEFAULT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,