You are here

function apachesolr_index_nodeapi_mass_delete in Apache Solr Search 8

Same name and namespace in other branches
  1. 6.3 apachesolr.index.inc \apachesolr_index_nodeapi_mass_delete()
  2. 7 apachesolr.index.inc \apachesolr_index_nodeapi_mass_delete()

Mass delete nodes from the solr indexer tables.

Parameters

array $nodes:

string $table:

Return value

boolean true if we mass updated, false if failed

1 call to apachesolr_index_nodeapi_mass_delete()
apachesolr_index_node_check_table in ./apachesolr.index.inc
hook_cron() helper to try to make the index table consistent with their respective entity table.

File

./apachesolr.index.inc, line 1429
Functions related to Apache Solr indexing operations.

Code

function apachesolr_index_nodeapi_mass_delete(array $nodes, $table = NULL) {
  if (empty($nodes)) {
    return TRUE;
  }
  if (empty($table)) {
    $table = apachesolr_get_indexer_table('node');
  }
  if (apachesolr_environment_variable_get(apachesolr_default_environment(), 'apachesolr_read_only', APACHESOLR_READ_WRITE) == APACHESOLR_READ_ONLY) {
    return TRUE;
  }
  $ids = array();
  $nids = array();
  foreach ($nodes as $node) {
    $ids[] = apachesolr_document_id($node->nid);
    $nids[] = $node->nid;
  }
  try {
    $env_id = apachesolr_default_environment();
    $solr = apachesolr_get_solr($env_id);
    $solr
      ->deleteByMultipleIds($ids);
    apachesolr_set_last_index_updated($env_id, REQUEST_TIME);

    // There was no exception, so update the table.
    db_delete($table)
      ->condition('entity_id', $nids, 'IN')
      ->execute();
    return TRUE;
  } catch (Exception $e) {
    watchdog('Apache Solr', nl2br(check_plain($e
      ->getMessage())), NULL, WATCHDOG_ERROR);
    return FALSE;
  }
}