Hi everyone,

I am experiencing a problem where a duplicate node of a content profile is being created for users every now and then. Users fill out one content profile type 'Profile' and when they save they have, for example, node 25 and node 26 both with the exact same fields filled out. This happens once about ever 50 'Profile' nodes created. This is strange not only because a duplicate is being created each time but because it also has content profile checked in the settings.

Can anyone please assist?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Bilmar’s picture

Title: duplicate node being created » Duplicates created on node creation (save clicked multiple times)
Priority: Normal » Major

Hello,

I have confirmed this is happening as well.

When creating the content profile node for the first time, if you click the SAVE button 5 times, then I get 5 duplicate content profile nodes. Looks to be a problem as many users tend to press the SAVE at least twice usually so the common problem is 2 nodes appearing with the same content, different node, both content profiles.

I am marking this as priority 'major' as this issue makes the purpose of this module (one content profile node of type x per user) not work properly.

I hope this issue can be looked into with the information provided.

Thank you very much in advance

rutiolma’s picture

I confirm this issue too.

dmetzcher’s picture

I am seeing this issue as well. It just happened the other day on one of my sites.

I'm assuming that it's OK to delete it (Is this correct?), but I am wondering why it's there in the first place. Other users seem to have confirmed my suspicion that it was created when a user clicked the Save button more than once. Can anything be done about this to stop it from happening?

Here's a little more detail, in case it helps...

When I edit both of these nodes (example: node/305/edit and node/306/edit), the user's profile page is only updated when I edit the first one that was created (in my example it has a lower node ID of 305, whereas the second one has a node ID of 306). Editing the second profile node that was created does not change the user's actual profile page (user/123). Also, when I update the user profile node via an edit to the user's actual profile page (user/123/edit), the first user profile node is updated. The second node just seems to be sitting out there, orphaned. It was identical to the first one when they were both created, but it's not being updated now and appears to be an orphan ("duplicate-orphan"?).

osopolar’s picture

I guess this is still active. I wondered why a user had two profile nodes. There needs to be a check on node validate or submission (before node_save()) if there is a already a profile node of the current type and user. In this case just give an error.

I guess there are two ways how a user currently could create two or more accounts: 1) hit save button more than once; 2) first open two node/add/profile pages and than submit each.

scttnlsn’s picture

It looks to me like there is already validation code in the nodapi hook that checks for the existence of a content profile for a particular type. If one already exists it sets an error on the form. The problem is that the validation is only performed if the current user has the permission "administer nodes". Is there a reason for this? I feel like the validation should be applied to anyone submitting the form.

AaronBauman’s picture

Another problem is that if node_save is called directly, no validation is performed at all.
The attached patch implements nodeapi::presave, looks for existing profile nodes, and assigns the existing nid to the node if it's not already set.

Note this will not eliminate existing duplicate profile nodes, but will prevent duplicate future profile nodes from being created by node_save().

AaronBauman’s picture

Status: Active » Needs review
jrstmartin’s picture

I haven't had issues with duplicate nodes on the latest dev release yet. I do have that issue with other node types, so I was going to apply your patch just to be safe, but it doesn't apply to the latest dev release. elseif statements are used instead of switch, so I'm not sure what was changed/improved here. Can you try the latest dev release without your patch and see if you get any dupes? Thanks!

fuzzy76’s picture

Issue summary: View changes

The patch in #6 won't apply. Actually, the nodeapi implementation in content_profile.module looks completely different from the one in the patch (uses if instead of switch and the line numbers are way off)? I also checked the changes done in the dev release, and couldn't find any that should be related to this bug.

fuzzy76’s picture

Status: Needs review » Active

Rewrote and added to the end of hook_nodeapi():

  elseif ($op == 'presave' && is_content_profile($node) && empty($node->nid)) {
    if ($existing_nid = db_result(db_query("SELECT nid FROM {node} WHERE uid = %d and type = '%s'", $node->uid, $node->type))) {
      $node->nid = $existing_nid;
  }

Too early to tell my results.

jvieille’s picture

I also get many duplicates when setting field values by rules, calling node_save.

I'll give a try to https://www.drupal.org/node/964490#comment-8660347
This code needs to be corrected though (missing "}"):

  elseif ($op == 'presave' && is_content_profile($node) && empty($node->nid)) {
    if ($existing_nid = db_result(db_query("SELECT nid FROM {node} WHERE uid = %d and type = '%s'", $node->uid, $node->type))) {
      $node->nid = $existing_nid;
    }
  }
fuzzy76’s picture

FileSize
617 bytes

Patch format

jukka792’s picture

Hi,

I am getting this when a user has administrator role.
Creating a page or taxonomy term creates a duplicate. create taxonomy term, click save and you get it twice.

UPDATE: The reason was MAC Safari 11.1, which caused the double submits when creating a node or taxonomy term etc.

mrgoodfellow’s picture

I am getting the same thing when creating any new content type.

At the '/node/add/content-type' page for any content type, when clicking 'Save' multiple times, multiple items are created.

Ideally the save button only allows one submit and all further 'obsessive' clicking is ignored.

This is occurring on a clean install (Drupal 7, not occuring in 8)