You are here

function apachesolr_attachments_is_parent_excluded in Apache Solr Attachments 7

Same name and namespace in other branches
  1. 6.3 apachesolr_attachments.module \apachesolr_attachments_is_parent_excluded()

Excludes a file if the parent_entity is set to status 0 or it is not being indexed

Parameters

type $entity_id:

type $entity_type:

Return value

type

1 call to apachesolr_attachments_is_parent_excluded()
apachesolr_attachments_apachesolr_file_exclude in ./apachesolr_attachments.module
Implenents hook_apachesolr_ENTITY_TYPE_exclude().

File

./apachesolr_attachments.module, line 439
Provides a file attachment search implementation for use with the Apache Solr module

Code

function apachesolr_attachments_is_parent_excluded($entity_id, $entity_type, $parent_entity_id, $parent_entity_type, $env_id) {
  $query = new EntityFieldQuery();
  $result = $query
    ->entityCondition('entity_type', $parent_entity_type)
    ->entityCondition('entity_id', $parent_entity_id)
    ->execute();

  // We only need the class and 1 item;
  if (empty($result)) {

    // Parent entity id does not exist anymore
    return TRUE;
  }
  $values = array_values($result[$parent_entity_type]);

  // Since we only expect 1 eid to return, we are going to do
  // a reset of the array
  $stub_entity = reset($values);
  $parent_entity_bundle = $stub_entity->type;

  // Ignore this parent if the bundles to be indexed for this entity type
  // are not indexed
  $bundles = apachesolr_get_index_bundles($env_id, $parent_entity_type);
  if (empty($bundles)) {

    // Exclude it
    return TRUE;
  }
  else {
    if (!in_array($parent_entity_bundle, $bundles)) {

      // Exclude it
      return TRUE;
    }
  }

  // Skip indexing of files if the node was excluded by apache solr
  $status_callbacks = apachesolr_entity_get_callback($parent_entity_type, 'status callback');
  if (!empty($status_callbacks)) {

    // Set status to true. Allow the callbacks to make the change
    $status = TRUE;

    // Check status callback before sending to the index
    foreach ($status_callbacks as $status_callback) {
      if (is_callable($status_callback)) {

        // by placing $status in front we prevent calling any other callback
        // after one status callback returned false
        $status = $status && $status_callback($parent_entity_id, $parent_entity_type);
      }
    }

    // TRUE means the status is ok. We should return FALSE so it does
    // not exclude
    return !$status;
  }

  // Exclude by default
  return TRUE;
}