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.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | webform-table-exist-check-sql-sanitize-2853810-14.patch | 993 bytes | dhrjgpt2005@gmail.com |
| #8 | webform-table-exist-check-sql-sanitize-2853810-8.patch | 1007 bytes | dhrjgpt2005@gmail.com |
Comments
Comment #2
dhrjgpt2005@gmail.com commentedComment #3
dhrjgpt2005@gmail.com commentedadded patch for the fix
Comment #5
dhrjgpt2005@gmail.com commentedComment #6
dhrjgpt2005@gmail.com commentedupdated patch
Comment #8
dhrjgpt2005@gmail.com commentedComment #9
dhrjgpt2005@gmail.com commentedComment #10
dhrjgpt2005@gmail.com commentedComment #11
skwashd commentedUpdated issue to use summary in order to explain the problem more clearly.
Comment #12
skwashd commentedAdding missing info to issue template
Comment #13
liam morlandThanks 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.
Comment #14
dhrjgpt2005@gmail.com commentedComment #15
dhrjgpt2005@gmail.com commented@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.
Comment #17
liam morlandThanks!