Problem/Motivation

When a drush command runs all drush plugins are loaded, regardless of if the module is enabled. The same applies to drush hooks, they fire if the module is enabled or not. For many sites this issue can be resolved by removing the unused modules. When running a large fleet of sites from a common platform/distribution this isn't a viable option.

In the case of webform the sql-sanitize command attempts to removed tables which may not be enabled for the site. This can reproduced by installing vanilla Drupal 7 and adding the webform module. When running drush sql-sanitize, the command will fail with the following error:

ERROR 1146 (42S02) at line 1: Table 'webform_submitted_data' doesn't exist

Proposed resolution

To fix this issue it is proposed to add checks to ensure that the tables exist before trying to empty them. If the tables don't exist, they don't need to be TRUNCATEd and so the sql commands are omitted.

Remaining tasks

This functionality wasn't covered by existing test coverage and testing it would be difficult as the webform module would have to be disabled for the tests to pass.

Original report by dhrjgpt2005

The "drush sql-sanitize" command now also purges all webform submissions.

While purging it does not check whether the webform tables present in database or not and include the truncate command for those tables which certainly fails with below error
...
ERROR 1146 (42S02) at line 1: Table 'webform_submitted_data' doesn't exist

So to fix the issue need to add a check before forming the truncate table sql query string.

A simple patch applying this approach will follow.

Comments

dhrjgpt2005 created an issue. See original summary.

dhrjgpt2005@gmail.com’s picture

dhrjgpt2005@gmail.com’s picture

Status: Active » Needs review

added patch for the fix

Status: Needs review » Needs work
dhrjgpt2005@gmail.com’s picture

dhrjgpt2005@gmail.com’s picture

Status: Needs work » Needs review

updated patch

Status: Needs review » Needs work
dhrjgpt2005@gmail.com’s picture

Status: Needs work » Needs review
StatusFileSize
new1007 bytes
dhrjgpt2005@gmail.com’s picture

dhrjgpt2005@gmail.com’s picture

skwashd’s picture

Issue summary: View changes

Updated issue to use summary in order to explain the problem more clearly.

skwashd’s picture

Issue summary: View changes

Adding missing info to issue template

liam morland’s picture

Status: Needs review » Needs work

Thanks for the patch. Please write it so that there is an array of tables which are candidates for deletion and only one copy of the in_array() code in a loop.

dhrjgpt2005@gmail.com’s picture

Status: Needs work » Needs review
StatusFileSize
new993 bytes
dhrjgpt2005@gmail.com’s picture

@Liam Morland I have updated the patch can you please have a look at it and let me know if it needs any more update.

liam morland’s picture

Title: Need to add Webforms Table exists check before truncation( drush sql-sanitize) » Only trancate tables that exist in drush sql-sanitize
Priority: Major » Normal
Status: Needs review » Fixed
Issue tags: -bug fix

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.