You are here

function apachesolr_entity_update in Apache Solr Search 6.3

Same name and namespace in other branches
  1. 8 apachesolr.module \apachesolr_entity_update()
  2. 7 apachesolr.module \apachesolr_entity_update()

Helper function for the hook_nodeapi().

1 call to apachesolr_entity_update()
apachesolr_nodeapi in ./apachesolr.module
Implements hook_nodeapi().

File

./apachesolr.module, line 1978
Integration with the Apache Solr search application.

Code

function apachesolr_entity_update($entity, $type) {
  module_load_include('inc', 'apachesolr', 'apachesolr.index');
  if (apachesolr_entity_should_index($entity, $type)) {
    $id = $entity->nid;
    $bundle = $entity->type;

    // Check status callback before sending to the index
    $status_callbacks = apachesolr_entity_get_callback($type, 'status callback', $bundle);
    $status = TRUE;
    if (is_array($status_callbacks)) {
      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($id, $type);
        }
      }
    }

    // Delete the entity from our index if the status callback returns FALSE
    if (!$status) {
      apachesolr_entity_delete($entity, $type);
      return;
    }
    $indexer_table = apachesolr_get_indexer_table($type);

    // If we haven't seen this entity before it may not be there, so merge
    // instead of update.
    $query = "INSERT INTO {{$indexer_table}} (entity_type, entity_id, bundle, status, changed)\n      VALUES ('%s', %d, '%s', %d, %d)\n      ON DUPLICATE KEY UPDATE entity_type = '%s', entity_id = %d, bundle = '%s', status = %d, changed = %d";
    db_query($query, array(
      $type,
      $id,
      $bundle,
      1,
      APACHESOLR_REQUEST_TIME,
      $type,
      $id,
      $bundle,
      1,
      APACHESOLR_REQUEST_TIME,
    ));
  }
}