I'm trying to create a rule to block a new user with a particular role, after the rule is added, when admin tries to add a new user with this role, I got the following exception:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2-4' for key 1: INSERT INTO {users_roles} (uid, rid) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1); Array ( [:db_insert_placeholder_0] => 2 [:db_insert_placeholder_1] => 4 ) in user_save() (line 595 of drupal-7.12\modules\user\user.module).
Setup: Newly installed D7.12 + Rules 7.x-2.0+16-dev + Entity API 7.x-1.0-rc1+34-dev with no other modules. Add new role "role1", add new rule:
{ "rules_block_role1_login" : {
"LABEL" : "Block role1 login",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules" ],
"ON" : [ "user_insert" ],
"IF" : [
{ "user_has_role" : { "account" : [ "account" ], "roles" : { "value" : { "4" : "4" } } } }
],
"DO" : [ { "user_block" : { "account" : [ "account" ] } } ]
}
}
Comments
Comment #1
kristiaanvandeneyndeSee unfixed (yet closed) issues #1169800: [Integrity constraint violation: 1062 Duplicate entry] On user registration and #1217772: Changing user after saving a new user cause a PDOException crash.
The workarounds near the bottom may help you.
Comment #2
mitchell commentedAssuming current issue state from #1.