You are here

function apachesolr_settings in Apache Solr Search 6.3

Same name and namespace in other branches
  1. 8 apachesolr.admin.inc \apachesolr_settings()
  2. 5.2 apachesolr.admin.inc \apachesolr_settings()
  3. 5 apachesolr.module \apachesolr_settings()
  4. 6 apachesolr.admin.inc \apachesolr_settings()
  5. 6.2 apachesolr.admin.inc \apachesolr_settings()
  6. 7 apachesolr.admin.inc \apachesolr_settings()

Form builder for general settings used as a menu callback.

1 string reference to 'apachesolr_settings'
apachesolr_menu in ./apachesolr.module
Implements hook_menu().

File

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

Code

function apachesolr_settings(&$form_state) {
  $form = array();
  $rows = array();

  // Environment settings
  $id = apachesolr_default_environment();
  $environments = apachesolr_load_all_environments();
  $default_environment = apachesolr_default_environment();
  apachesolr_check_facetapi();

  // Check if core search is still running
  if (variable_get('search_cron_limit', 0) != 0) {
    drupal_set_message(t('It seems that Drupal core search is not disabled.
      This can cause performance impact at cron runs.
      Please !url the per cron value to 0', array(
      '!url' => l('set', 'admin/settings/search'),
    )), 'warning');
  }

  // Reserve a row for the default one
  $rows[$default_environment] = array();
  foreach ($environments as $environment_id => $data) {

    // Define all the Operations
    $confs = array();
    $ops = array();

    // Whenever facetapi is enabled we also enable our operation link
    if (module_exists('facetapi')) {
      $confs['facets'] = array(
        'class' => 'operation',
        'data' => l(t('Facets'), 'admin/settings/apachesolr/settings/' . $data['env_id'] . '/facets', array(
          'query' => array(
            'destination' => $_GET['q'],
          ),
        )),
      );
    }

    // These are our result and bias settings
    if (module_exists('apachesolr_search')) {
      $confs['result_bias'] = array(
        'class' => 'operation',
        'data' => l(t('Bias'), 'admin/settings/apachesolr/settings/' . $data['env_id'] . '/bias', array(
          'query' => array(
            'destination' => $_GET['q'],
          ),
        )),
      );
    }
    $confs['index'] = array(
      'class' => 'operation',
      'data' => l(t('Index'), 'admin/settings/apachesolr/settings/' . $data['env_id'] . '/index'),
    );
    $ops['edit'] = array(
      'class' => 'operation',
      'data' => l(t('Edit'), 'admin/settings/apachesolr/settings/' . $data['env_id'] . '/edit', array(
        'query' => array(
          'destination' => $_GET['q'],
        ),
      )),
    );
    $ops['clone'] = array(
      'class' => 'operation',
      'data' => l(t('Clone'), 'admin/settings/apachesolr/settings/' . $data['env_id'] . '/clone', array(
        'query' => array(
          'destination' => $_GET['q'],
        ),
      )),
    );
    $env_name = l($data['name'], 'admin/settings/apachesolr/settings/' . $data['env_id'] . '/edit', array(
      'query' => array(
        'destination' => $_GET['q'],
      ),
    ));

    // Is this row our default environment?
    if ($environment_id == $default_environment) {
      $env_name = t('!environment <em>(Default)</em>', array(
        '!environment' => $env_name,
      ));
      $env_class_row = 'default-environment';
    }
    else {
      $env_class_row = '';

      // For every non-default we add a delete link
      // Allow to revert a search environment or to delete it
      $delete_value = '';
      if (!isset($data['in_code_only'])) {
        if (isset($data['type']) && $data['type'] == 'Overridden') {
          $delete_value = array(
            'class' => 'operation',
            'data' => l(t('Revert'), 'admin/settings/apachesolr/settings/' . $data['env_id'] . '/delete'),
          );
        }
        elseif ($environment_id != $default_environment) {
          $delete_value = array(
            'class' => 'operation',
            'data' => l(t('Delete'), 'admin/settings/apachesolr/settings/' . $data['env_id'] . '/delete'),
          );
        }
      }
      $ops['delete'] = $delete_value;
    }

    // When we are receiving a http POST (so the page does not show) we do not
    // want to check the statusses of any environment
    $class = '';
    if (empty($form_state['input'])) {
      $service_class_info = isset($data['conf']['service_class_info']) ? $data['conf']['service_class_info'] : NULL;
      $class = apachesolr_server_status($data['url'], $data['service_class'], $service_class_info) ? 'ok' : 'error';
    }
    $headers = array(
      array(
        'data' => t('Name'),
        'colspan' => 2,
      ),
      t('URL'),
      array(
        'data' => t('Configuration'),
        'colspan' => count($confs),
      ),
      array(
        'data' => t('Operations'),
        'colspan' => count($ops),
      ),
    );
    $rows[$environment_id] = array(
      'data' => array(
        // Cells
        array(
          'class' => 'status-icon',
          'data' => '<div title="' . $class . '"><span class="element-invisible">' . $class . '</span></div>',
        ),
        array(
          'class' => $env_class_row,
          'data' => $env_name,
        ),
        check_plain($data['url']),
      ),
      'class' => array(
        drupal_strtolower($class),
      ),
    );

    // Add the links to the page
    $rows[$environment_id]['data'] = array_merge($rows[$environment_id]['data'], $confs);
    $rows[$environment_id]['data'] = array_merge($rows[$environment_id]['data'], $ops);
  }
  $links['add_page'] = array(
    'title' => 'Add search environment',
    'href' => 'admin/settings/apachesolr/settings/add',
  );
  $form['apachesolr_host_settings']['actions'] = array(
    '#value' => '<ul class="action-links">' . theme('links', $links) . '</ul>',
  );
  $form['apachesolr_host_settings']['table'] = array(
    '#value' => theme('table', $headers, array_values($rows), array(
      'class' => array(
        'admin-apachesolr',
      ),
    )),
  );
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced configuration'),
    '#collapsed' => TRUE,
    '#collapsible' => TRUE,
  );
  $form['advanced']['apachesolr_set_nodeapi_messages'] = array(
    '#type' => 'radios',
    '#title' => t('Extra help messages for administrators'),
    '#description' => t('Adds notices to a page whenever Drupal changed content that needs reindexing'),
    '#default_value' => variable_get('apachesolr_set_nodeapi_messages', 1),
    '#options' => array(
      0 => t('Disabled'),
      1 => t('Enabled'),
    ),
  );

  // Number of Items to index
  $numbers = drupal_map_assoc(array(
    1,
    5,
    10,
    20,
    50,
    100,
    200,
  ));
  $default_cron_limit = variable_get('apachesolr_cron_limit', 50);

  // apachesolr_cron_limit may be overridden in settings.php. If its current
  // value is not among the default set of options, add it.
  if (!isset($numbers[$default_cron_limit])) {
    $numbers[$default_cron_limit] = $default_cron_limit;
  }
  $form['advanced']['apachesolr_cron_limit'] = array(
    '#type' => 'select',
    '#title' => t('Number of items to index per cron run'),
    '#default_value' => $default_cron_limit,
    '#options' => $numbers,
    '#description' => t('Reduce the number of items to prevent timeouts and memory errors while indexing.', array(
      '@cron' => url('admin/reports/status'),
    )),
  );
  $options = array(
    'apachesolr:show_error' => t('Show error message'),
  );
  foreach (module_implements('search_info') as $module) {

    // Don't allow apachesolr to return results on failure of apachesolr.
    if ($module == 'apachesolr_search') {
      continue;
    }
    $options[$module] = t('Show @name search results', array(
      '@name' => $module,
    ));
  }
  $options['apachesolr:show_no_results'] = t('Show no results');
  $form['advanced']['apachesolr_failure'] = array(
    '#type' => 'select',
    '#title' => t('On failure'),
    '#options' => $options,
    '#default_value' => variable_get('apachesolr_failure', 'apachesolr:show_error'),
  );
  return system_settings_form($form);
}