Posted by leon.nk on April 9, 2010 at 3:47pm
4 followers
| Project: | Webform |
| Version: | 6.x-3.0-beta4 |
| Component: | Code |
| Category: | task |
| Priority: | critical |
| Assigned: | abid.jhar |
| Status: | closed (works as designed) |
Issue Summary
So whenever form settings are saved, hook_webform_component_insert() is called for every component in that form.
I want to act upon when a component is inserted, so this extra call is causing me problems. The only way I can see to determine if the component has already been inserted is to do a db query, not the most ideal solution.
Thanks
Leon
Comments
#1
Hmm, yeah this is currently the way Webform does updates. In truth if you wanted to operate with it the way it is currently, you would need to implement hook_webform_component_delete() also, so that your items would be deleted and then re-inserted in the same way Webform does with the components.
Now I certainly agree that a more efficient approach here would be using update queries instead of delete/insert, so I'm moving this to a task.
#2
Hmm, okay looking at this it turns out that we *don't* call hook_webform_component_delete() before re-inserting. From webform_node_update():
// Update the webform by deleting existing data and replacing with the new.db_query('DELETE FROM {webform} WHERE nid = %d', $node->nid);
db_query('DELETE FROM {webform_component} WHERE nid = %d', $node->nid);
db_query('DELETE FROM {webform_roles} WHERE nid = %d', $node->nid);
webform_node_insert($node);
So we do have an API problem here (moving back to bug report). Doing an update is a bit of a problem here though, I imagine we'd need to node_load() the original node, then compare all of the components from the original and node being saved. Then we'd need to call the appropriate function: webform_component_update/delete/insert based on how each component changed.
#3
Here we are. This approach definitely is more verbose and requires a bit more effort, but the end result is a much more efficient process for node saving. Imagine if you had a node with 500 Webform components, doing a node_save() on that node requires 503 queries even if you didn't change anything about the Webform!
So this approach is much smarter, individually checking whether or not any component has changed and updating/inserting/deleting as necessary.
#4
While doing the Drupal 7 port, I discovered a problem with my "if no rows updated, then assume an insert" approach (more on that here: #718540: Better documentation in query.inc). It seems the only reliable test is to do a database query as a SELECT before determining if we need to do an insert or an update. So this patch takes that approach. Also attached is the D7 version.
#5
Quicksketch... that is some highly impressive module maintaining.
webform_node_update6.patch works perfectly. Thank you.
#6
Thanks, hoping that we can get a final release out soon. Thanks also for reporting this issue and testing! Committed to both 3.x branches.
#7
Automatically closed -- issue fixed for 2 weeks with no activity.
#8