function apachesolr_access_apachesolr_index_document_build_node in Apache Solr Search 7
Same name and namespace in other branches
- 8 apachesolr_access/apachesolr_access.module \apachesolr_access_apachesolr_index_document_build_node()
- 6.3 apachesolr_access/apachesolr_access.module \apachesolr_access_apachesolr_index_document_build_node()
Implements hook_apachesolr_index_document_build_node()
Add node access grants of generic view grants if node access is not used.
Parameters
$document: The document to add our node access information to
$node: The node which is used to built the document from
$env_id: The environment for which we are building the document. This parameter does not have any effect in this code so it can be ignored
1 call to apachesolr_access_apachesolr_index_document_build_node()
- 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 16
Code
function apachesolr_access_apachesolr_index_document_build_node(ApacheSolrDocument $document, $node, $env_id) {
$account =& drupal_static(__FUNCTION__);
if (!isset($account)) {
// Load the anonymous user.
$account = drupal_anonymous_user();
}
// When using a node access module like Domain Access which has
// access grants that vary for anonymous users for the same content,
// this variable should be set to 1. Note that doing so will prevent
// any results from being returned if using apachesolr_multisitesearch
// from a different site.
$always_add = apachesolr_environment_variable_get($env_id, 'apachesolr_access_always_add_grants', 0);
if ($always_add || !node_access('view', $node, $account)) {
// Get node access grants.
$result = db_query('SELECT * FROM {node_access} WHERE (nid = 0 OR nid = :nid) AND grant_view = 1', array(
':nid' => $node->nid,
));
foreach ($result as $grant) {
$grant_realm = apachesolr_access_clean_realm_name($grant->realm);
$key = 'access_node_' . apachesolr_site_hash() . '_' . $grant_realm;
$document
->addField($key, $grant->gid);
}
}
else {
// Add the generic view grant if we are not using
// node access or the node is viewable by anonymous users.
// We assume we'll never have an entity with the name '__all'.
$document
->addField('access__all', 0);
}
}