You are here

function apachesolr_file_solr_reindex in Apache Solr File 7

1 string reference to 'apachesolr_file_solr_reindex'
apachesolr_file_apachesolr_entity_info_alter in ./apachesolr_file.module

File

./apachesolr_file.module, line 69

Code

function apachesolr_file_solr_reindex() {
  $indexer_table = apachesolr_get_indexer_table('file');
  $transaction = db_transaction();
  $env_id = apachesolr_default_environment();
  try {
    db_delete($indexer_table)
      ->condition('entity_type', 'file')
      ->execute();
    if (apachesolr_get_index_bundles($env_id, 'file')) {
      $select = db_select('file_managed', 'f');
      $select
        ->addExpression("'file'", 'entity_type');
      $select
        ->addField('f', 'fid', 'entity_id');
      $select
        ->addField('f', 'type', 'bundle');
      $select
        ->addField('f', 'status', 'status');
      $select
        ->addExpression(REQUEST_TIME, 'changed');
      $select
        ->condition('f.type', apachesolr_get_index_bundles($env_id, 'file'), 'IN');
      $insert = db_insert($indexer_table)
        ->fields(array(
        'entity_id',
        'bundle',
        'status',
        'entity_type',
        'changed',
      ))
        ->from($select)
        ->execute();
    }
  } catch (Exception $e) {
    $transaction
      ->rollback();
    drupal_set_message($e
      ->getMessage(), 'error');
    watchdog_exception('Apache Solr', $e);
    return FALSE;
  }
  return TRUE;
}