You are here

function apachesolr_index_config_form_submit in Apache Solr Search 6.3

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

Submit handler for the bundle configuration form.

File

./apachesolr.admin.inc, line 1208
Administrative pages for the Apache Solr framework.

Code

function apachesolr_index_config_form_submit($form, &$form_state) {
  module_load_include('inc', 'apachesolr', 'apachesolr.index');
  $form_values = $form_state['values'];
  $env_id = $form_values['env_id'];
  $entity_count = 0;
  foreach ($form_values['entities'] as $entity_type => $bundles) {
    $existing_bundles = apachesolr_get_index_bundles($env_id, $entity_type);
    $all_bundles = array_keys($bundles);
    $new_bundles = array_values(array_filter($bundles));
    apachesolr_index_set_bundles($env_id, $entity_type, $new_bundles);

    // Remove all excluded bundles - this happens on form submit
    // even if there is no change so the admin can remove
    // bundles if there was an error.
    $excluded_bundles = array_diff($all_bundles, $new_bundles);
    if (apachesolr_index_delete_bundles($env_id, $entity_type, $excluded_bundles)) {
      $callback = apachesolr_entity_get_callback($entity_type, 'bundles changed callback');
      if (!empty($callback)) {
        call_user_func($callback, $env_id, $existing_bundles, $new_bundles);
      }
    }
    else {
      drupal_set_message(t('Search is temporarily unavailable. If the problem persists, please contact the site administrator.'), 'error');
    }
  }

  // Clear the content type cache, since we will be changing its data.
  content_clear_type_cache();
  cache_clear_all('apachesolr:environments', 'cache_apachesolr');
  drupal_set_message(t('Your settings have been saved.'));
}