You are here

function apachesolr_index_set_bundles in Apache Solr Search 8

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

Sets what bundles on the specified entity type should be indexed.

Parameters

string $env_id: The machine name of the environment.

string $entity_type: The entity type to index.

array $bundles: The machine names of the bundles to index.

Throws

Exception

7 calls to apachesolr_index_set_bundles()
apachesolr_environment_save in ./apachesolr.module
Function that saves an environment
apachesolr_index_config_form_submit in ./apachesolr.admin.inc
Submit handler for the bundle configuration form.
apachesolr_install in ./apachesolr.install
Implements hook_install().
apachesolr_node_type_delete in ./apachesolr.module
Implements hook_node_type_delete().
apachesolr_node_type_insert in ./apachesolr.module
Implements hook_node_type_insert().

... See full list

File

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

Code

function apachesolr_index_set_bundles($env_id, $entity_type, array $bundles) {
  $transaction = db_transaction();
  try {
    db_delete('apachesolr_index_bundles')
      ->condition('env_id', $env_id)
      ->condition('entity_type', $entity_type)
      ->execute();
    if ($bundles) {
      $insert = db_insert('apachesolr_index_bundles')
        ->fields(array(
        'env_id',
        'entity_type',
        'bundle',
      ));
      foreach ($bundles as $bundle) {
        $insert
          ->values(array(
          'env_id' => $env_id,
          'entity_type' => $entity_type,
          'bundle' => $bundle,
        ));
      }
      $insert
        ->execute();
    }
  } catch (Exception $e) {
    $transaction
      ->rollback();

    // Re-throw the exception so we are aware of the failure.
    throw $e;
  }
}