You are here

function apachesolr_access_build_subquery in Apache Solr Search 8

Same name and namespace in other branches
  1. 6.3 apachesolr_access/apachesolr_access.module \apachesolr_access_build_subquery()
  2. 7 apachesolr_access/apachesolr_access.module \apachesolr_access_build_subquery()

Creates a Solr query for a given user

Parameters

$account: an account to get grants for and build a solr query

Return value

SolrFilterSubQuery Instance of SolrFilterSubQuery

Throws

Exception

2 calls to apachesolr_access_build_subquery()
apachesolr_access_apachesolr_query_alter in apachesolr_access/apachesolr_access.module
Implements hook_apachesolr_query_alter().
DrupalApacheSolrNodeAccess::testIndexing in apachesolr_access/tests/apachesolr_access.test
Tests indexing and check if it adds the correct grants for those specific users

File

apachesolr_access/apachesolr_access.module, line 58

Code

function apachesolr_access_build_subquery($account) {
  if (!user_access('access content', $account)) {
    throw new Exception('No access');
  }
  $node_access_query = apachesolr_drupal_subquery();
  if (user_access('bypass node access', $account)) {

    // Access all content from the current site.
    $node_access_query
      ->addFilter('hash', apachesolr_site_hash());
  }
  else {

    // Get node access grants.
    $grants = node_access_grants('view', $account);
    foreach ($grants as $realm => $gids) {
      $realm = apachesolr_access_clean_realm_name($realm);
      foreach ($gids as $gid) {
        $node_access_query
          ->addFilter('access_node_' . apachesolr_site_hash() . '_' . $realm, $gid);
      }
    }
  }

  // Everyone can access public content. Note that if the variable
  // 'apachesolr_access_always_add_grants' is TRUE, no content from this site
  // is considered "public". However, this condition may match documents in
  // the Solr index supplied by other sites when multiple sites are indexing
  // into the same index , i.e. multisite search.
  $node_access_query
    ->addFilter('access__all', 0);
  return $node_access_query;
}