Attached files are deleted without usage checking. It causes lost of data in some cases.
@see http://cgit.drupalcode.org/webform/tree/src/Plugin/WebformElement/Webfor...
and
@see http://cgit.drupalcode.org/webform/tree/src/Plugin/WebformElement/Webfor...
Problem/Motivation
All managed files should have usage checked before deletion. In general, files in webforms are uploaded by user and won't be used in other places except for the submission entity that the file is uploaded. But in some cases, like when we set a default files in the file field, the same file entity will be used across multiple submissions. Deleting files without checking the usage will cause lost of data.
SUGGESTIONS
* Instead of directly deleting a file, we should delete file usages instead.
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 2952419-15.patch | 25.83 KB | jrockowitz |
| #10 | 2952419-10.patch | 10.48 KB | jrockowitz |
| #7 | 2952419-6.patch | 10.85 KB | jrockowitz |
Comments
Comment #2
jrockowitz commentedMakes sense to fix this. It is also worth noting, that the \Drupal\webform\WebformSubmissionStorage::delete() method also recursively deletes the 'webform/{webform_id}/{sid}' directory. This behavior probably needs to be removed.
Comment #3
jrockowitz commentedComment #4
jrockowitz commentedI just took a stab at addressing this and it is a lot more work than I expected. Still, I agree that the file usage should be deleted and not the actual file.
Comment #5
jrockowitz commentedAn unexpected issue I ran into is that we need account for files that have no remaining usages are no longer deleted by default.
I am not very comfortable with uploaded and then deleted webform submission files being orphaned and remaining indefinitely on the server. A webform might be collecting confidential information and when a submission is deleted all the files associated with that submission should to be deleted immediately.
I still think we need to check the file usage table and only delete webform submission upload files that are no longer being used.
Comment #7
jrockowitz commentedComment #10
jrockowitz commentedComment #12
keshavv commentedI have tested #10 patch.
Patch will fix the entire problem.
Comment #15
jrockowitz commentedThe attached patch adds additional test coverage for signature element's image.
Comment #17
jrockowitz commented