Skip to content

fix: Delete files on submission/question/form deletion#3335

Open
Koc wants to merge 1 commit into
mainfrom
feature/delete-files-on
Open

fix: Delete files on submission/question/form deletion#3335
Koc wants to merge 1 commit into
mainfrom
feature/delete-files-on

Conversation

@Koc
Copy link
Copy Markdown
Collaborator

@Koc Koc commented May 15, 2026

Closes #2676, #3061 (?)

Covered scenarios

Submission removal

We remove all files for that submission by file id. This means that we will remove file even if it has been moved outside of the form folder.

Question removal

We iterate though all submission and try to remove folder for the question for each submission by prefix {questionId} - . Imagine that we have next file structure:

  • forms/111 - my super form/3/22 - question1/file1.pdf
  • forms/111 - my super form/4/22 - question1 that was renamed/file2.pdf

And trying to remove question with id 22 Then we will remove all folders: 22 - question1 and 22 - question1 that was renamed.

At the same time if files were moved somewhere outside of the form directory - we will keep them as is.

⚠️ I doubt that this will work fast enough for form with 1000+ submissions. That's why I asked about async job for cleanup.

Form removal

We remove form folder completely by prefix {formId} - . Imagine that we have next file structure:

  • forms/111 - my super form/3/22 - question1/file1.pdf
  • forms/111 - my super form renamed/4/22 - question1 that was renamed/file2.pdf

And trying to remove form with id 111. Then we will remove all folders

At the same time if files were moved somewhere outside of the form directory - we will keep them as is.


⚠️ If you don't like this business logic - please explicitly explain how it should work for an each scenario and I will adjust code.

🚧 Todo

  • Add tests once I get approval for business logic

@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

❌ Patch coverage is 1.23457% with 80 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
lib/Db/AnswerMapper.php 0.00% 24 Missing ⚠️
lib/Controller/ApiController.php 4.76% 20 Missing ⚠️
lib/Db/SubmissionMapper.php 0.00% 19 Missing ⚠️
lib/Db/FormMapper.php 0.00% 17 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Koc Koc force-pushed the feature/delete-files-on branch 10 times, most recently from cb8497b to 00a550c Compare May 16, 2026 16:44
Signed-off-by: Kostiantyn Miakshyn <molodchick@gmail.com>
@Koc Koc force-pushed the feature/delete-files-on branch from 00a550c to 7c73eca Compare May 16, 2026 16:56
@Koc Koc marked this pull request as ready for review May 16, 2026 16:57
@Koc Koc requested review from Chartman123 and susnux May 16, 2026 16:57
Copy link
Copy Markdown
Collaborator

@Chartman123 Chartman123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had a first look into the PR and added some comments :)

* @param Form $form The form
* @param Question $question The question
*/
private function deleteQuestionFolder(Form $form, Question $question): void {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please move this to the bottom to the other helper functions? I'd like to have all directly accessible API functions come first.

Comment on lines +1789 to 1791
/** @var Folder $folder */

$fileName = $folder->getNonExistingName($uploadedFile['name']);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** @var Folder $folder */
$fileName = $folder->getNonExistingName($uploadedFile['name']);
/** @var Folder $folder */
$fileName = $folder->getNonExistingName($uploadedFile['name']);

Comment on lines +1865 to 1867
/** @var Folder $folder */

$file = $userFolder->getById($uploadedFile->getFileId())[0];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** @var Folder $folder */
$file = $userFolder->getById($uploadedFile->getFileId())[0];
/** @var Folder $folder */
$file = $userFolder->getById($uploadedFile->getFileId())[0];

Comment thread lib/Db/AnswerMapper.php
* @param int $questionId
* @return int[] Array of fileIds
*/
public function findFileIdsByQuestion(int $questionId): array {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function isn't referenced anywhere?

@Chartman123
Copy link
Copy Markdown
Collaborator

Regarding the logic:

  • for delete submission: shouldn't we delete only the folder containing the files for that submission, too? I would be prefer to never delete files automatically that are located outside the Forms folder by deleting anything in Forms.
  • async job would be fine for me, too, but probably adds more complexity

@Chartman123 Chartman123 requested a review from pringelmann May 18, 2026 13:55
@Chartman123 Chartman123 added 2. developing Work in progress bug Something isn't working labels May 18, 2026
@Chartman123 Chartman123 added this to the 5.3 milestone May 18, 2026
@Koc
Copy link
Copy Markdown
Collaborator Author

Koc commented May 18, 2026

I would be prefer to never delete files automatically that are located outside the Forms folder by deleting anything in Forms.

I thought that GDPR first and if user really wants to remove his submission - then we should cleanup everything 😄

@Chartman123
Copy link
Copy Markdown
Collaborator

I would be prefer to never delete files automatically that are located outside the Forms folder by deleting anything in Forms.

I thought that GDPR first and if user really wants to remove his submission - then we should cleanup everything 😄

Yes in this case it might make sense, but even then it depends on the contents of the file. In our use case we use the file questions for uploading music for events in our sports club. So when I delete a submission after adding the information to some other file I don't want to delete the file that I've moved to some other directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. developing Work in progress bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Delete uploaded files when answer is deleted

2 participants