/[drupal]/contributions/modules/apachesolr/contrib/apachesolr_nodeaccess/apachesolr_nodeaccess.module
ViewVC logotype

Diff of /contributions/modules/apachesolr/contrib/apachesolr_nodeaccess/apachesolr_nodeaccess.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.11.4.1, Tue Sep 22 15:26:16 2009 UTC revision 1.1.2.11.4.2, Thu Nov 5 17:17:21 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: apachesolr_nodeaccess.module,v 1.1.2.11 2009/06/05 18:05:06 robertDouglass Exp $  // $Id: apachesolr_nodeaccess.module,v 1.1.2.11.4.1 2009/09/22 15:26:16 claudiucristea Exp $
3    
4  /**  /**
5   * Implementation of apachesolr_update_index   * Implementation of apachesolr_update_index
6   */   */
7  function apachesolr_nodeaccess_apachesolr_update_index(&$document, $node) {  function apachesolr_nodeaccess_apachesolr_update_index(&$document, $node) {
8    static $account;    static $anonymous_account;
9      global $user;
10    
11    if (!isset($account)) {    // We have to run as anonymous while node_access() doesn't take the $user as
12      // Load the anonymous user.    // argument but we want to check the access as anonymous. We are using
13      $account = drupal_anonymous_user();    // http://drupal.org/node/218104 as a trick to safe switch to anonymous.
14      if ($user->uid) {
15        if (!isset($anonymous_account)) {
16          // Load the anonymous user.
17          $anonymous_account = drupal_anonymous_user();
18        }
19        $original_user = $user;
20        session_save_session(FALSE);
21        $user = $anonymous_account;
22    }    }
23    
24    if (!node_access('view', $node, $account)) {    if (!node_access('view', $node)) {
25      // Get node access grants.      // Get node access grants.
26      $result = db_query('SELECT * FROM {node_access} WHERE (nid = 0 OR nid = %d) AND grant_view = 1', $node->nid);      $result = db_query('SELECT * FROM {node_access} WHERE (nid = 0 OR nid = %d) AND grant_view = 1', $node->nid);
27      while ($grant = db_fetch_object($result)) {      while ($grant = db_fetch_object($result)) {
# Line 25  function apachesolr_nodeaccess_apachesol Line 34  function apachesolr_nodeaccess_apachesol
34      // node access or the node is viewable by anonymous users.      // node access or the node is viewable by anonymous users.
35      $document->setMultiValue('nodeaccess_all', 0);      $document->setMultiValue('nodeaccess_all', 0);
36    }    }
37    
38      // Switch back the original user
39      if (isset($original_user)) {
40        $user = $original_user;
41        session_save_session(TRUE);
42      }
43  }  }
44    
45  /**  /**
# Line 47  function _apachesolr_nodeaccess_build_su Line 62  function _apachesolr_nodeaccess_build_su
62    }    }
63    else {    else {
64      // Get node access grants.      // Get node access grants.
65      $grants = node_access_grants('view', $account);      $grants = node_access_grants('view', $account->uid);
66      foreach ($grants as $realm => $gids) {      foreach ($grants as $realm => $gids) {
67        foreach ($gids as $gid) {        foreach ($gids as $gid) {
68          $node_access_query->add_filter('nodeaccess_' . apachesolr_site_hash() . '_' . $realm, $gid);          $node_access_query->add_filter('nodeaccess_' . apachesolr_site_hash() . '_' . $realm, $gid);

Legend:
Removed from v.1.1.2.11.4.1  
changed lines
  Added in v.1.1.2.11.4.2

  ViewVC Help
Powered by ViewVC 1.1.2