Steps to reproduce:

- Create a node and make sure it's a group.
- Edit the node and remove the author (making it anonymous)
- FAIL.

When I first remove the checkbox for 'Group', then remove the author and re-enable de Group checkbox, it works.
So somewhere in the code, OG tries to add the anonymous user to the user table?

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'name': INSERT INTO {users} (uid, name, pass, mail, theme, signature, signature_format, created, access, login, status, timezone, language, picture, init, data, vid, ip) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14, :db_insert_placeholder_15, :db_insert_placeholder_16, :db_insert_placeholder_17); Array ( [:db_insert_placeholder_0] => 299 [:db_insert_placeholder_1] => [:db_insert_placeholder_2] => [:db_insert_placeholder_3] => [:db_insert_placeholder_4] => [:db_insert_placeholder_5] => [:db_insert_placeholder_6] => [:db_insert_placeholder_7] => 0 [:db_insert_placeholder_8] => 0 [:db_insert_placeholder_9] => 0 [:db_insert_placeholder_10] => 0 [:db_insert_placeholder_11] => [:db_insert_placeholder_12] => [:db_insert_placeholder_13] => 0 [:db_insert_placeholder_14] => [:db_insert_placeholder_15] => b:0; [:db_insert_placeholder_16] => 316 [:db_insert_placeholder_17] => ) in drupal_write_record() (line 6975 of /includes/common.inc).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

BarisW’s picture

Anyone?

BarisW’s picture

Version: 7.x-1.3 » 7.x-1.x-dev
Status: Active » Needs review
FileSize
511 bytes

Digging through the code, I found the following:

og_node_update() calls og_group() when the author of a node has changed. It doesn't check if UID == 0.
In the end of og_group() a entity_save() is called which does a user_save().

I'm not sure if this is a core bug (user_save() tries to create the user (and fails, as uid '' already exists).

I came up with the following, which works. I cannot determine if this has consequences somewhere else in the module logics, so please review.

<?php
     if (empty($account->uid)) {
      $values['save'] = FALSE;
    }
?>

Status: Needs review » Needs work

The last submitted patch, 1516108-og-removing-node-author-triggers-PDO.patch, failed testing.

BarisW’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1516108-og-removing-node-author-triggers-PDO.patch, failed testing.

Nephele’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1516108-og-removing-node-author-triggers-PDO.patch, failed testing.

Nephele’s picture

Status: Needs work » Needs review

#2: 1516108-og-removing-node-author-triggers-PDO.patch queued for re-testing.

The patch was failing originally because of #1748782: Existing 7.x-1.x-dev code always fails QA tests. The most recent failure was a testbot client malfunction. It now appears to have passed testing.

BarisW’s picture

Ah, that explains.

Would love to get some feedback on this from amibutai, whether this is the correct way to do it.

amitaibu’s picture

Status: Needs review » Needs work

It's probably better to move the $uid check directly into OgMembership->save

BarisW’s picture

Status: Needs work » Needs review
FileSize
626 bytes

It doesn't seem to get to OgEntity->save(). When I insert a die() in that place, it keeps working fine.
I've now added it just before <code>entity_save($entity_type, $entity); is called.

Is that any better?