I have a custom content type which reference many users.
I use the TAC lite module and view_own module in addition to the node access user reference module.

When i create or update any node of that content type, i get a duplicate entry warning.

See the full error below :

user warning: Duplicate entry '46-0-all' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (46, 'all', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2233.
user warning: Duplicate entry '46-0-all' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (46, 'all', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2233.
user warning: Duplicate entry '46-0-nodeaccess_userreference' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (46, 'nodeaccess_userreference', 0, 1, 1, 0) in /var/www/cedricm/modules/node/node.module on line 2233.
user warning: Duplicate entry '46-0-all' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (46, 'all', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2233.
user warning: Duplicate entry '46-0-nodeaccess_userreference' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (46, 'nodeaccess_userreference', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2233.
user warning: Duplicate entry '46-0-all' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (46, 'all', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2233.
user warning: Duplicate entry '46-0-nodeaccess_userreference' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (46, 'nodeaccess_userreference', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2233.
user warning: Duplicate entry '46-0-all' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (46, 'all', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2233.
user warning: Duplicate entry '46-0-nodeaccess_userreference' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (46, 'nodeaccess_userreference', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2233.
user warning: Duplicate entry '46-0-all' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (46, 'all', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2233.
user warning: Duplicate entry '46-0-nodeaccess_userreference' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (46, 'nodeaccess_userreference', 0, 1, 1, 0) in /var/www/cedricm/modules/node/node.module on line 2233.
user warning: Duplicate entry '46-0-all' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (46, 'all', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2233.
user warning: Duplicate entry '46-0-nodeaccess_userreference' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (46, 'nodeaccess_userreference', 0, 1, 1, 0) in /var/www/cedricm/modules/node/node.module on line 2233.
user warning: Duplicate entry '46-0-all' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (46, 'all', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2233.
user warning: Duplicate entry '46-0-nodeaccess_userreference' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (46, 'nodeaccess_userreference', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2233.

CommentFileSizeAuthor
#15 userref.patch2.18 KBgunzip
#12 noderef.patch1.98 KBgunzip
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

danielb’s picture

switch to 1.4 mate (older version) I'll get this fixed.

danielb’s picture

Status: Active » Fixed
PePiToO’s picture

Version: 6.x-1.5 » 6.x-1.6
Status: Fixed » Active

I just updated to the 6-1.6 version.
I did disable all the permissions module ( view_own and TAC lite ) , but there is still the same error when i enable the module and edit a node :

user warning: Duplicate entry '49-0-all' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (49, 'all', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2249.
user warning: Duplicate entry '49-0-all' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (49, 'all', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2249.
user warning: Duplicate entry '49-0-all' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (49, 'all', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2249.
user warning: Duplicate entry '49-0-nodeaccess_userreference' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (49, 'nodeaccess_userreference', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2249.
user warning: Duplicate entry '49-0-all' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (49, 'all', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2249.
user warning: Duplicate entry '49-0-nodeaccess_userreference' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (49, 'nodeaccess_userreference', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2249.
user warning: Duplicate entry '49-0-all' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (49, 'all', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2249.
user warning: Duplicate entry '49-0-nodeaccess_userreference' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (49, 'nodeaccess_userreference', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2249.
user warning: Duplicate entry '49-0-all' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (49, 'all', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2249.
user warning: Duplicate entry '49-0-nodeaccess_userreference' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (49, 'nodeaccess_userreference', 0, 1, 1, 0) in /var/www/cedricm/modules/node/node.module on line 2249.
user warning: Duplicate entry '49-0-all' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (49, 'all', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2249.
user warning: Duplicate entry '49-0-nodeaccess_userreference' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (49, 'nodeaccess_userreference', 0, 1, 1, 0) in /var/www/cedricm/modules/node/node.module on line 2249.
user warning: Duplicate entry '49-0-all' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (49, 'all', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2249.
user warning: Duplicate entry '49-0-nodeaccess_userreference' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (49, 'nodeaccess_userreference', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2249.

danielb’s picture

damn, the 1.6 version is just the same as the 1.5 version... I should have checked. I don't know how this happens I've definitly commited updated code.
I'm making a 1.7 and I will check to make sure.

danielb’s picture

Status: Active » Fixed

ok she looks sweet

PePiToO’s picture

Status: Fixed » Active

i just updated and it seems to do the same problem again whether i save/rebuild content permission :

user warning: Duplicate entry '49-0-nodeaccess_userreference' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (49, 'nodeaccess_userreference', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2249.
user warning: Duplicate entry '49-0-nodeaccess_userreference' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (49, 'nodeaccess_userreference', 0, 1, 0, 0) in /var/www/cedricm/modules/node/node.module on line 2249.

It seems to work though

danielb’s picture

That's not the problem I fixed. I don't quite know what that is - can you try resaving node/49 ?

danielb’s picture

Status: Active » Postponed (maintainer needs more info)
PePiToO’s picture

Note that i am using Content Access 6.x-1.0 as well.
When i give a higher priority to Content Access module, it works fine ( as your module have less priority so the error does not come out ), but everytime your module have the priority, each time a node is saved this error appear.

Any idea ?

gunzip’s picture

This happens to me if I use more than userreference cck field for a content type and two or more of them reference the same user.
More generally the access system is trying to assign different permissions to the same couple user => node.

If you use another content access module with higher priority this doesn't happen as the grants from userreference access
module are probably ignored in that case and not inserted into the table.

Technical info: this happens if the $grants array is populated with multiple permissions for the same uid => nid.
I think there should be a check in the foreach loop to use only the highest permissions.

Scenario:

1. two userreference fields points to the same user

2. the first one gives me the following rights: (view=1, delete=0, edit=0)

3. the second one gives me: (view=1, delete=1, edit=1)

then __only__ the second grants should be inserted into the array (i think).

I fixed this "hacking" the node access user reference module keying the grant array

$grants[$uid_$nid] = $grant

updating it only if the $grant variable contains higher rights, finally return array_values
(it's quite dirty so i'm not posting a patch)

PePiToO’s picture

Any update on this ? will it be fixed in the next release ?

gunzip’s picture

FileSize
1.98 KB

can you test this patch and give some feedback please ? thank you.

danielb’s picture

Status: Postponed (maintainer needs more info) » Active

I think a much simpler solution would be to construct the $grants array as $grants['uid']['grant_something'] instead of $grants[]['grant_something'], this would build the grants properly without having to check for the field that gives 'highest access'. The function node_access_acquire_grants() does not care about the keys of the array, so we can use it as an easy way to build unique records.
No need to use 'uid_nid' as everything in that function should be unique to one particular node.

danielb’s picture

Here is how I would do it. Sorry I don't have time to set this up and test it atm.

<?php


/**
 * Implementation of hook_node_access_records().
 */
function nodeaccess_userreference_node_access_records($node) {
  $grants = array();
  $info = content_fields(NULL, $node->type);
  if (is_array($info)) {
    foreach ($info as $field) {
      if ($field['type'] == 'userreference') {
        $view_name = "nodeaccess_userreference_" . $field['field_name'] . '_' . $field['type_name'];
        $update_name = "nodeaccess_userreference_" . $field['field_name'] . '_' . $field['type_name'] . '_update';
        $delete_name = "nodeaccess_userreference_" . $field['field_name'] . '_' . $field['type_name'] . '_delete';
        $grant_view = variable_get($view_name, 0);
        $grant_update = variable_get($update_name, 0);
        $grant_delete = variable_get($delete_name, 0);
        if (($grant_view || $grant_update || $grant_delete) && is_array($node->$field['field_name'])) {
          foreach ($node->$field['field_name'] as $userreference) {
            $uid = &$userreference['uid'];
            if (!isset($grants[$uid])) {
              $grants[$uid] = array(
                'realm' => 'nodeaccess_userreference',
                'gid' => $uid,
                'priority' => 0,
              );
            }
            if ($grant_view) {
              $grants[$uid]['grant_view'] = 1;
            }
            if ($grant_update) {
              $grants[$uid]['grant_update'] = 1;
            }
            if ($grant_delete) {
              $grants[$uid]['grant_delete'] = 1;
            }
          }
        }
      }
    }
  }
  if (!empty($grants)) {
    return $grants;
  }
  return NULL;
}



?>

gunzip’s picture

Status: Active » Needs review
FileSize
2.18 KB

clever indeed. i made a patch with your code (to be tested).

PePiToO’s picture

This patch seems to work fine, thank you !

No more errors on create/edit projects with multiple users referenced more than 1 time and the access is working fine.

artis’s picture

+1 for this patch working! I've applied it and it solved the issues I was having too. This should definitely get committed in the next release IMO.

artis’s picture

Version: 6.x-1.6 » 6.x-1.7
danielb’s picture

Status: Needs review » Fixed

I've added this to the 2.0 betas

gunzip’s picture

i've seen in the latest beta you've dropped out the condition

if (!isset($grants[$uid])) {
              $grants[$uid] = array(...

but i think this was important because it assures that the privileges are the greatest possibile
(between multiple userreference in the same node) while without it the privileges gained are just the latest found,
(sorry if i'm wrong)

danielb’s picture

oops

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.