Submission Export Scheduler
The firing and handling of the WPCron intervals happens in the SubmissionExportScheduler class. The plugin uses Ninja Forms core functionality to handle the retrieval and exporting of submissions. Much of the functionality was added into core at versions 3.6.x, so this plugin must be run with core versions 3.6.10 and higher. Since much of the handling happens inside core, the most important linkage to understand is how this plugin interacts with core.
Retrieving the Intended Submissions
In core, submissions are retrieved using the SubmissionAggregate
class. This class, when properly constructed using the SubmissionAggregateFactory
class, is aware of all data sources, such as Ninja Forms' custom post type and Caldera Forms' data table.
A SubmissionFilter
object is created to retrieve the submissions, but this must happen in two steps.
First the export schedule parameters are converted into SubmissionFilter object. Note that one of the export parameters is the date of the last exported submission. That time stamp (plus one second) is used as the starting date for the new filter so that the submissions begin where the previous export left off.
After retrieving the meta data for the remaining submissions, this collection is 'sliced' by the maxCount
parameter so that only the request number of submissions are included in this scheduled export. The submission date of this currently slice is set as the new last exported
timestamp, which will be used to start the next scheduled export.
The sliced collection is passed into core's CSV export class to create the CSV output. (We may add more output formats in the future, but currently the only available export format is CSV.)
Core's TempFileWriter
class writes each export to a temporary file, after which that file is attached and emailed, followed by the deletion of the temp file. (Again, we may add additional delivery methods in the future, but currently only email delivery is available.)