Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Drush provides a feature called sql-sanitize that helps to delete data that shouldn't leave a production environment.
A drush file with these contents are all you should need.
function webform_drush_sql_sync_sanitize($site) {
drush_sql_register_post_sync_op('webform_submitted_data',
dt('Delete all data submitted to webforms (depending on the site config, may contain sensitive data).'),
"TRUNCATE webform_submitted_data;");
}
If there are other tables that webform stores data in, then please do add them in a similar fashion.
Comment | File | Size | Author |
---|---|---|---|
#11 | webform-sql_sync_sanitize-2555051-11.patch | 763 bytes | DanChadwick |
Comments
Comment #2
gregglesComment #3
gregglesComment #4
DanChadwick CreditAttribution: DanChadwick commentedLooking at the sql implementation, do we have to deal with table prefixes?
http://api.drush.org/api/drush/commands%21sql%21sync.sql.inc/function/sq...
This goes in the drush file with the drush commands?
Shall we delete submissions too, which contain a record of when and who submitted the webform? If we don't, then we will have empty submission (which is fine if that's what is desired)
Comment #5
gregglesI suggest deleting submissions as well. I was looking for big tables.
I'm not sure there is a good way to deal with prefixes in these hooks. I think people with prefixes are used to the feature not working for them.
Comment #6
DanChadwick CreditAttribution: DanChadwick commentedThere's a bit of a problem with doing this in bulk. Every component gets a chance to delete something, and then every module gets a chance at deleting. See webform_submission_delete().
Also see the related issue with clearing large numbers of submissions.
And if webform_results_clear uses the batch api, then we could loop through all webform nodes. This could be written to not consume unlimited memory, but it could take a verrrry long time.
Can drush commands use the batch api?
Comment #7
DanChadwick CreditAttribution: DanChadwick commentedGreg -- Can you clarify what is desired here?
I am in the process of creating a drush command to delete a node's submissions, which is slightly related to this issue.
Comment #8
gregglesI think 2 is ideal, but I'm not sure that drupal is bootstrapped sufficiently to achieve it. It's worth trying it out.
Comment #9
DanChadwick CreditAttribution: DanChadwick commentedI thought that Drupal was fully bootstrapped for drush commands. I just wrote a drush command that deletes the submissions for one node. This command would do the same but for all webform nodes.
We can see if it is useful. Could be hours of execution for really bit databases.
Comment #10
gregglesFor a random drush command, it is, sure. For sql-sanitize it might not be. Can you try that in sql-sanitize?
Comment #11
DanChadwick CreditAttribution: DanChadwick commentedAck. I don't think a proper job is possible. Consider:
Regardless of the bootstrap question, the hook is invoked before the confirmation for the purpose of building SQL commands. I think the best we can do is truncate the relevant databases.
Here's a patch. Someone else can test this, please.
Comment #12
DanChadwick CreditAttribution: DanChadwick commentedNo testing? :( Well, let's commit it since I'm pretty confident that the SQL is correct it it follows Greg's template.
Committed to 7.x-4.x.
Comment #14
DanChadwick CreditAttribution: DanChadwick commentedNeeds up-port to D8.
Comment #15
fenstratCommitted and pushed to 8.x-4.x.