You are here

function apachesolr_attachments_apachesolr_file_exclude in Apache Solr Attachments 7

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

Implenents hook_apachesolr_ENTITY_TYPE_exclude().

This is invoked for each file entity that is being inspected to be added to the index. if any module returns TRUE, the entity is skipped for indexing.

Parameters

integer $entity_id:

integer $row: A complete set of data from the indexing table.

string $env_id:

Return value

boolean

File

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

Code

function apachesolr_attachments_apachesolr_file_exclude($entity_id, $row, $env_id) {
  module_load_include('inc', 'apachesolr_attachments', 'apachesolr_attachments.index');

  // Make sure we have a boolean value.
  // Anything different from 1 becomes zero
  if (!$entity_id || !$row->parent_entity_id) {

    // Exclude
    return TRUE;
  }

  // Check if the parent entity is excluded
  $parent_entity_id = $row->parent_entity_id;
  $parent_entity_type = $row->parent_entity_type;
  $exclude = apachesolr_attachments_is_parent_excluded($entity_id, 'file', $parent_entity_id, $parent_entity_type, $env_id);
  if ($exclude) {

    // Exclude
    return TRUE;
  }

  // Exclude files above the configured limit.
  $filesize_limit = variable_get('apachesolr_attachments_filesize_limit', '41943040');

  // load the entity.
  $entities = entity_load('file', array(
    $entity_id,
  ), NULL, TRUE);

  // Take the first item.
  $entity = reset($entities);

  // Check if the filesize is higher than the allowed filesize.
  if (isset($entity->filesize) && $filesize_limit > 0 && $entity->filesize > $filesize_limit) {
    watchdog('Apache Solr Attachments', 'Excluding file @filename with size @filesize bytes, which exceeds apachesolr_attachments_filesize_limit of @sizelimit bytes.', array(
      '@filesize' => $entity->filesize,
      '@filename' => $entity->filename,
      '@sizelimit' => $filesize_limit,
    ));
    return TRUE;
  }

  // Do not exclude
  return FALSE;
}