Following installation of userprotect, when I attempted to submit the user permissions form I would get the following error:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2-change own e-mail' for key 'PRIMARY': INSERT INTO {role_permission} (rid, permission, module) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => 2 [:db_insert_placeholder_1] => change own e-mail [:db_insert_placeholder_2] => userprotect ) in user_role_grant_permissions() (line 2865 of C:\wamp\www\drupal7\modules\user\user.module).
I discovered that uninstalling and reinstalling would result in the same error immediately after install. This appeared to result from attempts to update the userprotect permissions in the {role_permission} table when the "module" column had a blank value. Because the permissions weren't being cleared out on uninstall (the system couldn't find them), the error would pop up immediately on a reinstall.
Fixed this by assigning the module name in hook_install():
foreach ($permissions as $permission) {
db_insert('role_permission')
->fields(array(
'rid' => DRUPAL_AUTHENTICATED_RID,
'permission' => $permission,
'module' => 'userprotect',
))->execute();
}
Comments
Comment #1
hunmonk commentedcommitted a fix to HEAD, thanks for the catch!
Comment #2
Ellen Dee commentedHappy to help. Great module! Thanks for porting.