You are here

function apachesolr_index_nodeapi_mass_update in Apache Solr Search 7

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

Mass Update nodes from the solr indexer table TODO: This always assumes the default environment!

Parameters

array $nodes:

string $table:

Return value

boolean true if we mass updated, false if failed

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 1464
Functions related to Apache Solr indexing operations.

Code

function apachesolr_index_nodeapi_mass_update(array $nodes, $table = NULL) {
  if (empty($nodes)) {
    return TRUE;
  }
  if (empty($table)) {
    $table = apachesolr_get_indexer_table('node');
  }
  $env_id = apachesolr_default_environment();
  if (apachesolr_index_env_is_readonly($env_id)) {
    apachesolr_index_report_readonly($env_id);
    return FALSE;
  }
  $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 {
    $solr = apachesolr_get_solr($env_id);
    $solr
      ->deleteByMultipleIds($unpublished_ids);
    apachesolr_set_last_index_updated($env_id, REQUEST_TIME);

    // There was no exception, so update the table.
    if ($published_ids) {
      db_update($table)
        ->fields(array(
        'changed' => REQUEST_TIME,
        'status' => 1,
      ))
        ->condition('entity_id', array_keys($published_ids), 'IN')
        ->execute();
    }
    if ($unpublished_ids) {
      db_update($table)
        ->fields(array(
        'changed' => REQUEST_TIME,
        'status' => 0,
      ))
        ->condition('entity_id', array_keys($unpublished_ids), 'IN')
        ->execute();
    }
    return TRUE;
  } catch (Exception $e) {
    apachesolr_log_exception($env_id, $e);
    return FALSE;
  }
}