You are here

function apachesolr_confgen_form_validate in Apache Solr Config Generator 7

Same name and namespace in other branches
  1. 6 apachesolr_confgen.admin.inc \apachesolr_confgen_form_validate()

Implements hook_form_validate().

_state

Parameters

$form:

Return value

void

File

./apachesolr_confgen.admin.inc, line 81
Schema generator

Code

function apachesolr_confgen_form_validate(&$form, &$form_state) {
  ob_clean();
  ob_start();

  // Seems to be a bug in core that $form_state['clicked_button']['#name'] is not always correct
  // Workaroud: Use button| prefix
  $button = '';
  foreach (array_keys($form_state['input']) as $button) {
    if (strpos($button, 'button|') === 0) {
      break;
    }
  }
  list(, $type, $solr_version) = explode('|', str_replace('_', '.', $button));
  variable_realm_switch('solr_version', $solr_version);
  drupal_add_http_header('Expires: ', gmdate('D, d M Y H:i:s') . ' GMT');
  drupal_add_http_header('Cache-Control:', 'must-revalidate, post-check=0, pre-check=0');
  drupal_add_http_header('Pragma:', 'public');
  switch ($type) {
    case 'currency':
    case 'elevate':
    case 'schema':
    case 'solrconfig':
      $qp = apachesolr_confgen_get_original_qp($type, $solr_version);
      drupal_alter('apachesolr_confgen_' . $type, $qp, $solr_version);
      drupal_add_http_header('Content-Type', 'text/xml; charset=utf-8');
      drupal_add_http_header('Content-Disposition', 'attachment; filename=' . $type . '.xml');
      ob_end_clean();
      print $qp
        ->find(':root')
        ->xml();
      exit;
    case 'zip':

      // array for zip content
      $files = array();
      foreach (array(
        'currency',
        'elevate',
        'schema',
        'solrconfig',
      ) as $file) {
        if ('currency' == $file && strpos($solr_version, '1.') === 0) {
          continue;
        }
        $qp = apachesolr_confgen_get_original_qp($file, $solr_version);
        drupal_alter('apachesolr_confgen_' . $file, $qp, $solr_version);
        $files[$file . '.xml'] = $qp
          ->find(':root')
          ->xml();
      }
      if (strpos($solr_version, '1.') !== 0) {
        $solrcore_properties = apachesolr_confgen_parse_properties(apachesolr_confgen_load_config_file(apachesolr_confgen_get_local_path($solr_version) . 'solrcore.properties'));
        drupal_alter('apachesolr_confgen_solrcore_properties', $solrcore_properties, $solr_version);
        array_walk($solrcore_properties, 'apachesolr_confgen_create_solrcore_properties_lines');
        $files['solrcore.properties'] = implode("\n", $solrcore_properties);
      }
      drupal_alter('apachesolr_confgen_zip_file', $files, $solr_version);
      require_once dirname(__FILE__) . '/lib/apachesolr_confgen_zipfile.php';
      $zip = new apachesolr_confgen_zipfile();
      foreach ($files as $file_name => $file_data) {
        $zip
          ->addFile($file_data, $file_name);
      }
      drupal_add_http_header('Content-Type:', 'application/x-gzip');
      drupal_add_http_header('Content-Disposition:', 'inline; filename="apachesolr_config_' . $solr_version . '.zip"');
      ob_end_clean();
      print $zip
        ->file();
      exit;
  }
}