You are here

function apachesolr_index_get_entities_to_index in Apache Solr Search 7

Same name and namespace in other branches
  1. 8 apachesolr.index.inc \apachesolr_index_get_entities_to_index()
  2. 6.3 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

Parameters

$env_id:

$entity_type:

$limit:

Return value

array list of row to index

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 497
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;
  }

  // Get next batch of entities to index
  $query = _apachesolr_index_get_next_set_query($env_id, $entity_type);
  $query
    ->range(0, $limit);
  $records = $query
    ->execute();
  $status_callbacks = array();
  foreach ($records as $record) {
    if (!isset($status_callbacks[$record->bundle])) {
      $status_callbacks[$record->bundle] = apachesolr_entity_get_callback($entity_type, 'status callback', $record->bundle);
    }

    // Check status and status callbacks before sending to the index
    if (is_array($status_callbacks[$record->bundle])) {
      foreach ($status_callbacks[$record->bundle] 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;
}