function apachesolr_entity_update in Apache Solr Search 8
Same name and namespace in other branches
- 6.3 apachesolr.module \apachesolr_entity_update()
- 7 apachesolr.module \apachesolr_entity_update()
Implements hook_entity_update().
1 call to apachesolr_entity_update()
- apachesolr_entity_insert in ./
apachesolr.module - Implements hook_entity_insert().
File
- ./
apachesolr.module, line 1958 - Integration with the Apache Solr search application.
Code
function apachesolr_entity_update($entity, $type) {
// Include the index file for the status callback
module_load_include('inc', 'apachesolr', 'apachesolr.index');
if (apachesolr_entity_should_index($entity, $type)) {
$info = entity_get_info($type);
list($id, $vid, $bundle) = entity_extract_ids($type, $entity);
// 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.
// The entity being saved is passed to the status callback in
// addition to $id in case the callback needs to examine properties
// such as the current node revision which cannot be determined by
// loading a fresh copy of the entity.
$status = $status && $status_callback($id, $type, $entity);
}
}
}
// Delete the entity from our index if the status callback returns FALSE
if (!$status) {
apachesolr_entity_delete($entity, $type);
return NULL;
}
$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.
db_merge($indexer_table)
->key(array(
'entity_type' => $type,
'entity_id' => $id,
))
->fields(array(
'bundle' => $bundle,
'status' => 1,
'changed' => REQUEST_TIME,
))
->execute();
}
}