It's not working right. I have a view which shows nodes behind nodeaccess for certain roles. I need this view without nodeaccess, to I used your module. As a result, the view results completely disappeared.

Below are my queries, BEFORE and AFTER.

Query BEFORE:

SELECT node.nid AS nid,
   node_data_field_photo.field_photo_fid AS node_data_field_photo_field_photo_fid,
   node_data_field_photo.field_photo_list AS node_data_field_photo_field_photo_list,
   node_data_field_photo.field_photo_data AS node_data_field_photo_field_photo_data,
   node.type AS node_type,
   node.vid AS node_vid,
   node.title AS node_title,
   node_data_field_photo.field_location_value AS node_data_field_photo_field_location_value,
   node_data_field_photo.field_email_email AS node_data_field_photo_field_email_email,
   node_revisions.body AS node_revisions_body,
   node_revisions.format AS node_revisions_format
 FROM node node 
 INNER JOIN content_type_people node_data_field_user_type ON node.vid = node_data_field_user_type.vid
 LEFT JOIN content_type_people node_data_field_photo ON node.vid = node_data_field_photo.vid
 LEFT JOIN node_revisions node_revisions ON node.vid = node_revisions.vid
 WHERE (node.status <> 0) AND (node.type in ('people')) AND (node_data_field_user_type.field_user_type_value = 'mt')
   ORDER BY node_title ASC

Result: 4 (protected by node access)

Query AFTER:

SELECT node.nid AS nid,
   node_data_field_photo.field_photo_fid AS node_data_field_photo_field_photo_fid,
   node_data_field_photo.field_photo_list AS node_data_field_photo_field_photo_list,
   node_data_field_photo.field_photo_data AS node_data_field_photo_field_photo_data,
   node.type AS node_type,
   node.vid AS node_vid,
   node.title AS node_title,
   node_data_field_photo.field_location_value AS node_data_field_photo_field_location_value,
   node_data_field_photo.field_email_email AS node_data_field_photo_field_email_email,
   node_revisions.body AS node_revisions_body,
   node_revisions.format AS node_revisions_format
 FROM node node 
 INNER JOIN content_type_people node_data_field_user_type ON node.vid = node_data_field_user_type.vid
 LEFT JOIN content_type_people node_data_field_photo ON node.vid = node_data_field_photo.vid
 LEFT JOIN node_revisions node_revisions ON node.vid = node_revisions.vid
 WHERE (node.status <> 0) AND (node.type in ('people')) AND (node_data_field_user_type.field_user_type_value = 'mt')
   ORDER BY node_title ASC

Result: 0

Comments

Anonymous’s picture

Oh I noticed there is no difference in the above queries (strange?) - but still after adding your filter, the view has no more results.

-EDIT-

this is the problem, in views_ignore_node_permissions.module:

$result = db_query_range($query, $args, $offset, $view->pager['items_per_page']);

My $view->pager['items_per_page'] is 0 (= "all"). So you need to add a check:

if ($view->pager['items_per_page'] == 0):
  $result = db_query($query, $args);
else:
  $result = db_query_range($query, $args, $offset, $view->pager['items_per_page']);
endif;
Anonymous’s picture

Despite my above fix, it still does not work.

You also need to set the module weight to > 10+

In system db table, find views_node_etc.. and set weight=10. I set it to 100 to be sure. This needs to go in a .intall file.

crystaldawn’s picture

The query change is done in hook views_pre_render() so thats probably why you dont see the query change. It shouldnt need any weight changes since render is the very last function called anyways. It is completely possible that the if statement I have in the pre_render hook isnt firing for your site. I've tried several different methods to detect if the filter is enabled or not but not entirely sure if what I ended with will encompass all scenerios. A quick way to see if this module will even work for you is to comment this line and see if your view starts showing the expected results (which would be nodes that the user doesnt have permissions to see normally).

if (is_object($view->display[$view->current_display]->handler->handlers['filter']['ignore_node_permissions']))
   {

to

//if (is_object($view->display[$view->current_display]->handler->handlers['filter']['ignore_node_permissions']))
   {

If this doesnt help, then the query that is in the pre-render isnt working for your site for some reason and it would be good to find out why so that it can be modified to encompass your setup as well. If it DOES help, then I would need the $views object for your view so I could see why the if statement isnt functioning properly.

Anonymous’s picture

The module works for me now, but like I mentioned in #1, you need to check for $view->pager['items_per_page'] = 0 (=all). Also I had to change the module weight, perhaps due to other module conflicts.

But definitely check my patch in #1, it is needed.

nikhil.goyal’s picture

Priority: Normal » Major

I have the same problem, the views result completely vanished once I used this module, on my views.

I'm using content access module, to restrict content on per node basis.

If required my the module maintainer I will be glad to show him the site, so he can see the problem.

Edit --

I was able to fix this problem after setting my "Items To Display" to 200 from 0.

Thanks for this module.

crystaldawn’s picture

This seems to be a problem when setting 0 as the Limit (items to display). I'll have a look at this thanx.

interestingaftermath’s picture

I have mine set on limit 5 (with no pager) and I have the same problem. Nothing is showing.

thekevinday’s picture

I can confirm this problem exists and also confirm that the solution from #1 works.

Edit: might as well do the following:

This code:
$offset = $view->pager['current_page'] * $view->pager['items_per_page'] + $view->pager['offset'];
Is only needed with the db_query_range() function, so put this inside of the else brackets.

dkane’s picture

I too can confirm the problem and the solution in #5 worked for me (setting the number of displayed values to anything other than 0).

I didn't want to go mucking around in the module, but glad that it sounds like a quick fix for the next RC.

Thanks so much for this module and your help with it, it saved me!

thekevinday’s picture

#5 happens to work because db_query() is not being properly called in the original code when needed.

#1 is a proper fix of the issue.

hnln’s picture

It didn't work for me because I had a node translation filter and ***CURRENT_LANGUAGE*** didn't get replaced (as it was an arugment).

fix:

below line 18:

$args = $view->build_info['query_args'];

add :

if (is_array($args)) {
  foreach ($args as $id => $arg) {
    $args[$id] = str_replace(array_keys($replacements), $replacements, $arg);
  }
}

(also taken form view.inc)

dave kopecek’s picture

Had same issue here with offset. Fix in #1 and move of $offset to inside of else as suggested in #8 worked for me.

Patch attached.

gooddesignusa’s picture

thanks this worked for me on one view. But on another I still get this error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near &#039;LIMIT 0, 20&#039; at line 1 query: LIMIT 0, 20 in /home/**/public_html/**/sites/all/modules/views_ignore_node_permissions/views_ignore_node_permissions.module on line 25.

If the view has results it is fine but if you goto the view before it has any results is when you get the error. To make the view not show anything without submitting I have a global null set in the args. With provide default arg with php code selected using this code:

if (count($view->exposed_input)) {
  return TRUE;
}

If I remove the global null from the args it works fine.

webchick’s picture

Title: Not working - hides results completely » Views set to show "unlimited" values hide results completely
Status: Active » Needs review
StatusFileSize
new1.47 KB

I can confirm this bug when you have a view set to 0 (unlimited) results. I can also confirm that this patch works as intended.

The vague title of this issue is leading this to become a dumping ground of every possible problem with this module that people are having. Re-scoping in an effort to stop that. I've also re-rolled the patch to:

a) conform to coding standards
b) use git
c) touch up the comments a bit

I would mark it RTBC, but I'm technically the last person to touch this patch, so I'll leave it "needs review".

Thanks so much for this great module! It's exactly what I needed for my use case: being able to reference organic groups in a node reference field without also making content editors members of all groups.

webchick’s picture

And for folks having this problem who don't know how to apply a patch, a cheap workaround for now is to set your view limit to something like 99999 instead of 0.

dave kopecek’s picture

#12 >> a) conform to coding standards

Doh! Schooled by webchick on coding standards. Now I'm afraid that Santa knows when I've been bad too.

webchick’s picture

LOL! :) No offense intended; thanks a lot for the patch!

jwilson3’s picture

Status: Needs review » Reviewed & tested by the community

Tested and confirmed the patch in #14 works.