when trying to clone a webform in 3.x i get messages like

4 times
Warning: Table 'watchdog' was not locked with LOCK TABLES query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (3, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:12:\"user warning\";s:8:\"%message\";s:819:\"Duplicate entry '34608-1' for key 1\nquery: INSERT INTO webform_component (nid, cid, pid, form_key, name, type, value, extra, mandatory, weight) VALUES (34608, 1, 0, 'texttext', 'texttext', 'textfield', '', 'a:11:{s:8:\\"disabled\\";i:0;s:5:\\"width\\";s:0:\\"\\";s:9:\\"maxlength\\";s:0:\\"\\";s:12:\\"field_prefix\\";s:0:\\"\\";s:12:\\"field_suffix\\";s:0:\\"\\";s:11:\\ in /home/web/includes/database.mysqli.inc on line 128

and then an error message on the next regular page for each field of the form

user warning: Duplicate entry '34608-3' for key 1 query: INSERT INTO webform_component (nid, cid, pid, form_key, name, type, value, extra, mandatory, weight) VALUES (34608, 3, 0, 'your_name', 'Your Name', 'textfield', '%username', 'a:11:{s:8:\"disabled\";i:0;s:5:\"width\";s:0:\"\";s:9:\"maxlength\";s:0:\"\";s:12:\"field_prefix\";s:0:\"\";s:12:\"field_suffix\";s:0:\"\";s:11:\"description\";s:0:\"\";s:10:\"attributes\";a:0:{}s:6:\"unique\";i:0;s:21:\"conditional_component\";s:0:\"\";s:20:\"conditional_operator\";s:1:\"=\";s:18:\"conditional_values\";s:0:\"\";}', 1, 1) in /home/sites/swdx/web/sites/all/modules/webform/includes/webform.components.inc on line 635.

Finally the node was created, but surely without components and without any email setup.

I think this should be fixed in webform and not in node clone.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

miro_dietiker’s picture

BTW: there was not even a message about the emails. So it seems the emails wouldn't get cloned this way any more.

This might need an additional workaround then.

roball’s picture

Title: webform node clone error » Webform nodes no longer can be cloned
Version: 6.x-3.x-dev » 6.x-3.0-beta5
Priority: Normal » Critical

Oh damned - confirmed with beta 5. I get no warning or error message in the browser, and the dblog doesn't contain any indication of failure either, but the clone does not contain any component and has no e-mail setup.

In the webserver's error log, PHP warnings like this appear:

PHP Warning:  Table 'watchdog' was not locked with LOCK TABLES\nquery: INSERT INTO watchdog\n    (uid, type, message, variables, severity, link, location, referer, hostname, timestamp)\n    VALUES\n    (1, 'php', '%message in %file on line %line.', 'a:4:{s:6:\\"%error\\";s:12:\\"user warning\\";s:8:\\"%message\\";s:608:\\"Duplicate entry '347-5' for key 'PRIMARY'\\nquery: INSERT INTO webform_component (nid, cid, pid, form_key, name, type, value, extra, mandatory, weight) VALUES (347, 5, 0, 'user_profile_data', 'User profile data', 'fieldset', '', 'a:6:{s:11:\\\\"collapsible\\\\";i:1;s:9:\\\\"collapsed\\\\";i:1;s:20:\\\\"conditional_operator\\\\";s:1:\\\\"=\\\\";s:11:\\\\"description\\\\";s:0:\\\\"\\\\";s:21:\\\\"conditional_component\\\\";s:0:\\\\" in /usr/share/drupal/includes/database.mysqli.inc on line 128, referer: https://www.iseki-food.eu/drupal/node/347/clone
quicksketch’s picture

Priority: Critical » Normal
Status: Active » Fixed
FileSize
708 bytes

This looks like it was a regression introduced by #766780: hook_webform_component_insert() is called when form settings are saved. I got too carried away in a clean up and removed a line that (seemingly) had no purpose. Oddly I already even had a code comment saying that the segment of code was "Used with clone.module" but I seemed to overlook it. I've re-added this line with a more explicit comment so that I don't delete it again.

quicksketch’s picture

I found another similar bug that occurs when doing a node_load(), changing a webform component, then doing a node_save(). This should prevent problems in the future with this API bug. It does not affect the normal usage of Webform though, since creating and editing a component normally does not use node_save() to save the changed component.

roball’s picture

Status: Fixed » Needs work

Thank you - with Webform 6.x-3.x-dev (2010-Apr-14) the "Form components" tab was populated again, which is of course the most important part to be cloned :-) There are also no problems with cloning the contents of the "Form settings" tab.

The only thing which still won't be cloned is the stuff in the "E-mails" tab, which is however not really that important.

miro_dietiker’s picture

Confirm -dev to work properly for components.

Yes, still missing email notification setup to be cloned...

The clone module might should introduce something like a hook to let modules duplicate the extended node (content) itself. Webforms could then react on that and duplicate things that are out of scope of a regular node_load into the new node.

miro_dietiker’s picture

If we're adding a node translation using i18n, the components won't be copied in current -dev. Only the base form information is there. Is this a different issue and needs a different ticket?

quicksketch’s picture

Yes, please open a different issue. It seems that node cloning works alright right now in dev for at least components.

miro_dietiker’s picture

Added translation duplication implementation request:
#774206: Add webform components on translation.module duplication

roball’s picture

Is cloning of the E-mails settings being planned to be re-included in 6.x-3.0?

quicksketch’s picture

Yes, cloning including the e-mail settings will be added to 3.x shortly.

candelas’s picture

thanks quicksketch
now i have to make it by hand but for transllation it will be great :)

roball’s picture

I would be happy to test the fix in 3.x immediately when it's committed.

wylbur’s picture

Installed the 6.x-3.0-beta5 version today, and get errors that were very similar to the errors listed in comment #2. Rather than post them here, I can confirm that the problem was resolved by applying the patch in comment #3.

I also applied the patch in #4, but did this did not seem to have any effect either way - the patch in comment #3 worked with and without the patch in comment #4.

Thanks.

roball’s picture

Yes, you should either go with the current 6.x-3.x-dev version or apply patch from #4 to beta5.

donquixote’s picture

same problem here, subscribe.

miro_dietiker’s picture

To make the emails clone there's only needed to add:
webform.module ~@850
in function webform_node_insert

  module_load_include('inc', 'webform', 'includes/webform.emails');
  // ... right after the components insert ...

    // Insert emails
    foreach ($node->webform['emails'] as $eid => $email) {
      $email['nid'] = $node->nid;
      $neweid = webform_email_insert($email);
    }

Don't forget to add this code also to the translation case...

roball’s picture

Great - I think if you attach this fix as a patch, then quicksketch may consider to commit it so we have the fix in the next beta. Thanks.

quicksketch’s picture

Status: Needs work » Fixed
FileSize
4 KB

I've committed this patch which should include e-mails when nodes are cloned, edited, inserted, or deleted. Just like components, we need not only to do inserts, but also updates which are more complicated. While looking at emails I also found that we hadn't been removing email settings *at all*, meaning that an update function was also in order to clean up any orphaned e-mail settings.

Please review and reopen if there are any lingering problems. This patch has already been committed.

roball’s picture

This now works fine in 6.x-3.0-beta6. Thanks!

Status: Fixed » Closed (fixed)

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