function drush_webform_clear in Webform 7.4
Clears a webform via drush.
This is useful for webforms with many submissions that would otherwise fail due to time out due or memory consumption.
Parameters
int $nid: Node ID of the webform to clear.
File
- ./
webform.drush.inc, line 179 - Functions relating to Drush integration.
Code
function drush_webform_clear($nid = FALSE) {
if (!$nid) {
return drush_set_error('The node ID of the webform to be cleared is required.');
}
$node = node_load($nid);
if (!$node) {
return drush_set_error(dt('Node !nid was not found.', array(
'!nid' => $nid,
)));
}
if (!drush_confirm(dt('Clear submissions from webform "@title"?', array(
'@title' => $node->title,
)))) {
return drush_set_error('webform-clear cancelled.');
}
// @code
// module_load_include('inc', 'webform', 'includes/webform.submissions');
// module_load_include('inc', 'webform', 'includes/webform.components');
// @endcode
module_load_include('inc', 'webform', 'includes/webform.report');
// Pull in option from drush to override the default.
$batch_size = drush_get_option('batch-size', 10000);
$count = 0;
while ($deleted = webform_results_clear($nid, $batch_size)) {
$count += $deleted;
}
// Alas, there is no drush version of format_plural, so use the ugly "(s)".
drush_log(dt('@count submission(s) in webform "@title" cleared.', array(
'@count' => $count,
'@title' => $node->title,
)), 'ok');
}