Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When I edit a group membership for a user in a group whose status is "Active", and assigning a role, the membership has updated. But when I change the user status to "Pending", the user status has been changed and the role is "unchecked". Then, when I try to change the user status to "Active" and assigning the role gives me the following error
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '3-3-1' for key 'PRIMARY': INSERT INTO {og_users_roles} (uid, rid, gid, group_type) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => 3 [:db_insert_placeholder_1] => 3 [:db_insert_placeholder_2] => 1 [:db_insert_placeholder_3] => node ) in drupal_write_record() (line 7239 of /var/www/ogdemo/includes/common.inc).
This is because the role I assigned to the user still exists but the role is "unchecked" visually while in the edit page. Need a workaround for this issue.
Comment | File | Size | Author |
---|---|---|---|
#5 | 2380967-5_og_role_grant_throws_pdo_exception.patch | 1.78 KB | rbayliss |
| |||
#4 | 2380967-3_og_role_grant_throws_pdo_exception-testonly.patch | 1.35 KB | rbayliss |
#1 | og-duplicate-entry-og_users_roles-2380967-1.patch | 556 bytes | criznach |
Comments
Comment #1
criznach CreditAttribution: criznach commentedI found that og_role_grant() was not loading existing roles for non-active users. I changed the default $check_active flag for a call to og_get_user_roles() to FALSE, and the error appears to be fixed. This makes it load existing role records even if the user is not active. Then drupal_write_record does not try and overwrite them.
Comment #2
amitaibuCan we add a simpleTest here as-well?
Comment #4
rbayliss CreditAttribution: rbayliss at Last Call Media commentedHere is a simpletest demonstrating the problem. When called on an existing membership that already has a role and is not in the active state, og_role_grant fails to detect the presence of the existing role, and tries to write another record. This should fail.
Comment #5
rbayliss CreditAttribution: rbayliss at Last Call Media commentedHere's the whole thing. This should pass.
Comment #6
jrbThe patch in #5 is working for me.
Comment #7
peterpearson CreditAttribution: peterpearson commented#5 resolves this issue.
Comment #8
Flow1990 CreditAttribution: Flow1990 commentedSame problem when you switch status between "Active", to user status "blocked", the user status has been changed and the role is "unchecked" and cause an error.
I use this to patch problem :
Comment #9
rbayliss CreditAttribution: rbayliss at Last Call Media commented@amitaibu - Anything further needed on this one? We've got a fix and a test.
Comment #10
zeev CreditAttribution: zeev as a volunteer commented#5 fixed the pdo exception.
Comment #12
amitaibuMerged, thanks! (Sorry for the late merge, I tend to be a little more quicker when it's a PR to GitHub)
Comment #14
rbayliss CreditAttribution: rbayliss at Last Call Media commentedAwesome. Thanks!
Comment #15
Xilis CreditAttribution: Xilis at BigScreen Group commentedThere is an addition to this fix on github, specifically this issue/this PR.
The same issue persists when trying to change status back to active and assign an existing role to a currently blocked user.
Comment #16
denzabasa CreditAttribution: denzabasa commented#5 works for me. Thanks!