ok so here is how to do that.. you need to create a module and set Drupal cron to run once a day on your hosting provider
then you need your webform to have email unique then do this ....
/**
* Implements hook_cron().
*/
function YOURMODULE_cron() {
$current_month = date('m');
// Get first month of quarter
$new_month = (3 * floor(($current_month - 1 ) / 3)) + 1;
$new_month = substr('0' . $new_month, -2);
$first_quarter_day_date = date('Y') . '-' . $new_month . '-01';
$today = date('Y-m-d');
// So this is the first day of the quarter.
if ($first_quarter_day_date == $today) {
// Use cache to make sure this runs once.
$cid = 'clear_out_webform_date';
$cached = \Drupal::cache()->get($cid);
$run = TRUE;
if (!empty($cached)) {
if (!empty($cached->data['date'])) {
if ($cached->data['date'] == $today) {
$run = FALSE;
}
}
}
if ($run == TRUE) {
// change this to your webform id
$webform_id = 'contact';
// Export all submissions to file.
$webform = \Drupal\webform\Entity\Webform::load($webform_id);
$submission_exporter = \Drupal::service('webform_submission.exporter');
$export_options = $submission_exporter->getDefaultExportOptions();
$export_options['delimiter'] = ';';
$export_options['multiple_delimiter'] = ',';
$submission_exporter->setWebform($webform);
$submission_exporter->setExporter($export_options);
$submission_exporter->generate();
$file_path = $submission_exporter->getExportFilePath();
// rename the file to something good.
$filename = $today.'-export.csv';
$uri = 'public://' . $filename;
$fileContent = file_get_contents($file_path);
$destination = $uri;
// Save the file to be a file entity.
$file = file_save_data(
$fileContent,
$destination,
FILE_EXISTS_RENAME
);
if (is_object($file)) {
// Probably email your self a reminder here.
// ^^ file is now an entity so you can do something like.
// load a know entity and append the file to a document field.
// or just download it as in the public file dir.
// Delete previous quarter submissions.
$query = \Drupal::entityQuery('webform_submission')
->condition('webform_id', $webform_id);
$result = $query->execute();
if (!empty($result)) {
$webform_submission_storage = \Drupal::entityTypeManager()->getStorage('webform_submission');
$submissions = $webform_submission_storage->loadMultiple($result);
foreach ($submissions as $submission) {
$submission->delete();
}
}
}
// set the cache to today so it wont run again.
\Drupal::cache()->set($cid, ['date' => $today]);
}
}
}
have fun and good luck.