You are here

function _apachesolr_attachments_update_parent_entity in Apache Solr Attachments 7

trigger an apachesolr_entity_update of parents where the parents are flagged for indexing attachments with the parent

2 calls to _apachesolr_attachments_update_parent_entity()
apachesolr_attachments_entity_insert in ./apachesolr_attachments.module
apachesolr_attachments_entity_update in ./apachesolr_attachments.module

File

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

Code

function _apachesolr_attachments_update_parent_entity($entity, $type) {

  // if this entity was being indexed with its parent, we need to trigger a reindex of the parent
  $parents = file_get_file_references($entity, NULL, FIELD_LOAD_CURRENT);
  $parents_list = $parents ? reset($parents) : NULL;
  if (!empty($parents_list)) {
    foreach ($parents_list as $parent_entity_type => $parent) {
      foreach ($parent as $parent_entity_id => $parent_info) {

        // load the parent entity and reset cache
        $parent_entities = entity_load($parent_entity_type, array(
          $parent_entity_id,
        ), NULL, TRUE);

        // Take the first entity from the stack
        $parent_entity = reset($parent_entities);

        // Skip invalid entities
        if (empty($parent_entity)) {
          continue;
        }

        // get the bundle
        list($parent_entity_id, $parent_entity_vid, $parent_entity_bundle) = entity_extract_ids($parent_entity_type, $parent_entity);
        if (variable_get('apachesolr_attachments_entity_bundle_indexing_' . $parent_entity_bundle, 'seperate') == 'parent') {
          apachesolr_entity_update($parent_entity, $parent_entity_type);
        }
      }
    }
  }
}