You are here

function apachesolr_index_nodeapi_mass_update in Apache Solr Search 6.3

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

Mass Update nodes from the solr indexer table

Parameters

type $nodes:

type $table:

Return value

type

1 call to apachesolr_index_nodeapi_mass_update()
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 1285
Functions related to Apache Solr indexing operations.

Code

function apachesolr_index_nodeapi_mass_update($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;
  }
  $published_ids = array();
  $unpublished_ids = array();
  foreach ($nodes as $node) {
    if ($node->status) {
      $published_ids[$node->nid] = apachesolr_document_id($node->nid);
    }
    else {
      $unpublished_ids[$node->nid] = apachesolr_document_id($node->nid);
    }
  }
  try {
    $env_id = apachesolr_default_environment();
    $solr = apachesolr_get_solr($env_id);
    $solr
      ->deleteByMultipleIds($unpublished_ids);
    apachesolr_set_last_index_updated($env_id, APACHESOLR_REQUEST_TIME);

    // There was no exception, so update the table.
    if (count($published_ids)) {
      $query = "UPDATE {{$table}} asn SET asn.changed = '%s' WHERE asn.entity_id IN (" . db_placeholders($published_ids) . ")";
      db_query($query, array_merge(array(
        APACHESOLR_REQUEST_TIME,
      ), $published_ids));
    }
    if (count($unpublished_ids)) {
      $query = "UPDATE {{$table}} asn SET asn.changed = '%s', asn.status = 0 WHERE asn.entity_id IN (" . db_placeholders($unpublished_ids) . ")";
      db_query($query, array_merge(array(
        APACHESOLR_REQUEST_TIME,
      ), $unpublished_ids));
    }
    return TRUE;
  } catch (Exception $e) {
    watchdog('Apache Solr', nl2br(check_plain($e
      ->getMessage())), NULL, WATCHDOG_ERROR);
    return FALSE;
  }
}