[5.x] Support filtering form submissions export #12014
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR comes as result of a client who wanted to prefilter form submissions before exporting them. Since Statamic already has a very robust filtering system, all that was needed was to allow the filters to be parsed by the exporters.
It also reworks how the export is actually performed to be less memory intensive by using lazy loading on the query and writing to the file during the loop rather than at the end.
I will note it is not ideal the code from the two query() methods is duplicated from:
https://github.com/statamic/cms/blob/5.x/src/Query/Scopes/Filters/Concerns/QueriesFilters.php
and
https://github.com/statamic/cms/blob/5.x/src/Http/Controllers/CP/Forms/FormSubmissionsController.php#L15-L63
It may be better to extract that filtering/ordering code into somewhere more central like the SubmissionQueryBuilder or SubmissionRepository.
I also did not see any tests in regards to the exports; let me know if I should create some.