When saving a node that has more than one nodereference field, a slew of SQL errors occurs.
I tracked it down to the following code, which appears to insert several copies of the same grant (one for each nodereference field), but I'm not sure what it's actually supposed to be doing:
if ($field['module'] == 'nodereference') {
$nid = $node->{$field_name}[0]['nid'];
$uid = $node->uid;
$type = $field['type_name'];
$permission = $edit_via_ref_content;
$edit_perm = in_array($permission, $default_permissions[$rid]) ? 1 : 0;
$permission = $delete_via_ref_content;
$delete_perm = in_array($permission, $default_permissions[$rid]) ? 1 : 0;
$view_any_content = $view_via_ref_content;
$view_perm = (($edit_perm || $delete_perm) ? 1 : in_array($view_any_content, $default_permissions[$rid]));
$grants[] = array(
'realm' => 'view_own_owner',
'gid' => $uid,
'grant_view' => $view_perm,
'grant_update' => $edit_perm,
'grant_delete' => $delete_perm,
'priority' => 0,
);
}
Also, the code just below that for userreferences appears to assume that no two userreference fields on the node will reference the same user, if they do, I think it will give the same errors:
$grants[] = array(
'realm' => 'view_own_owner',
'gid' => $uid,
'grant_view' => $view_perm,
'grant_update' => $edit_perm,
'grant_delete' => $delete_perm,
'priority' => 0,
);
Comments
Comment #1
restyler commentedI got the same problem.
There is no sense in multiple grants[] entries, for the same node, for same realm and with same gid.
I think I've fixed that, just replace
in view_own_node_access_records()
with
Comment #2
asak commented+1 for the fix by restyler above
Didn't go over it - just tried it and it seems to solve this problem.
Comment #3
thesleuth commentedWas having the same issue. The fix above works for us. Patch?
Comment #4
kenorb commentedComment #5
kenorb commentedThis (#3) look like workaround, any reason why does it happen?
Comment #6
kenorb commented