You are here

function apachesolr_nodeapi_mass_update in Apache Solr Search 5.2

Same name and namespace in other branches
  1. 6 apachesolr.index.inc \apachesolr_nodeapi_mass_update()
  2. 6.2 apachesolr.index.inc \apachesolr_nodeapi_mass_update()
1 call to apachesolr_nodeapi_mass_update()
apachesolr_cron_check_node_table in ./apachesolr.index.inc
hook_cron() helper to try to make {apachesolr_search_node} consistent with {node}.

File

./apachesolr.index.inc, line 299
Functions used when indexing content to Apache Solr.

Code

function apachesolr_nodeapi_mass_update($nodes) {
  if (empty($nodes)) {
    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);
    }
  }
  $time = time();
  try {
    $solr = apachesolr_get_solr();
    $solr
      ->deleteByMultipleIds($unpublished_ids);
    apachesolr_index_updated($time);

    // There was no exception, so update the table.
    if ($published_ids) {
      db_query('UPDATE {apachesolr_search_node} SET changed = %d, status = 1 WHERE nid IN (' . db_placeholders($published_ids) . ')', array_merge((array) $time, array_keys($published_ids)));
    }
    if ($unpublished_ids) {
      db_query('UPDATE {apachesolr_search_node} SET changed = %d, status = 0 WHERE nid IN (' . db_placeholders($unpublished_ids) . ')', array_merge((array) $time, array_keys($unpublished_ids)));
    }
    return TRUE;
  } catch (Exception $e) {
    watchdog('Apache Solr', nl2br(check_plain($e
      ->getMessage())), WATCHDOG_ERROR);
    return FALSE;
  }
}