You are here

function apachesolr_index_get_entities_to_index in Apache Solr Search 6.3

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

Returns an array of rows from a query based on an indexing environment. @todo Remove the read only because it is not environment specific

4 calls to apachesolr_index_get_entities_to_index()
apachesolr_drush_solr_get_next_indexed in drush/apachesolr.drush.inc
apachesolr_get_nodes_to_index in ./apachesolr.module
Function to retrieve all the nodes to index. Deprecated but kept for backwards compatibility
apachesolr_index_entities in ./apachesolr.index.inc
Processes all index queues associated with the passed environment.
DrupalSolrNodeTestCase::testApacheSolrNodeReindex in tests/apachesolr_base.test

File

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

Code

function apachesolr_index_get_entities_to_index($env_id, $entity_type, $limit) {
  $rows = array();
  if (apachesolr_environment_variable_get($env_id, 'apachesolr_read_only', APACHESOLR_READ_WRITE) == APACHESOLR_READ_ONLY) {
    return $rows;
  }
  $bundles = apachesolr_get_index_bundles($env_id, $entity_type);
  if (empty($bundles)) {
    return $rows;
  }

  // Drupal 6 specifically only supports nodes
  $type = 'node';
  if ($type != $entity_type) {
    return $rows;
  }

  // Get next batch of entities to index
  $query = _apachesolr_index_get_next_set_query($env_id, $entity_type);
  $result = db_query_range($query['query'], $query['args'], 0, $limit);
  $status_callbacks = apachesolr_entity_get_callback($entity_type, 'status callback');
  while ($record = db_fetch_object($result)) {

    // Check status and status callbacks before sending to the index
    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
          $record->status = $record->status && $status_callback($record->entity_id, $record->entity_type);
        }
      }
    }
    $rows[] = $record;
  }
  return $rows;
}