You are here

public function SolrConfigSetController::getConfigFiles in Search API Solr 8.3

Same name and namespace in other branches
  1. 4.x src/Controller/SolrConfigSetController.php \Drupal\search_api_solr\Controller\SolrConfigSetController::getConfigFiles()

Returns the configuration files names and content.

Return value

array An associative array of files names and content.

Throws

\Drupal\search_api\SearchApiException

1 call to SolrConfigSetController::getConfigFiles()
SolrConfigSetController::getConfigZip in src/Controller/SolrConfigSetController.php
Returns a ZipStream of all configuration files.

File

src/Controller/SolrConfigSetController.php, line 233

Class

SolrConfigSetController
Provides different listings of SolrFieldType.

Namespace

Drupal\search_api_solr\Controller

Code

public function getConfigFiles() : array {

  /** @var \Drupal\search_api_solr\SolrBackendInterface $backend */
  $backend = $this
    ->getBackend();
  $connector = $backend
    ->getSolrConnector();
  $solr_branch = $real_solr_branch = $connector
    ->getSolrBranch($this->assumedMinimumVersion);
  $solr_major_version = $connector
    ->getSolrMajorVersion($this->assumedMinimumVersion);
  $template_path = drupal_get_path('module', 'search_api_solr') . '/solr-conf-templates/';
  $solr_configset_template_mapping = [
    '6.x' => $template_path . '6.x',
    '7.x' => $template_path . '7.x',
    // Solr 8.x uses the same schema and solrconf as 7.x. So we can use the
    // same templates and only adjusts luceneMatchVersion to 8.
    '8.x' => $template_path . '7.x',
  ];
  $this
    ->moduleHandler()
    ->alter('search_api_solr_configset_template_mapping', $solr_configset_template_mapping);
  $search_api_solr_conf_path = $solr_configset_template_mapping[$solr_branch];
  $solrcore_properties = parse_ini_file($search_api_solr_conf_path . '/solrcore.properties', FALSE, INI_SCANNER_RAW);
  $files = [
    'schema_extra_types.xml' => $this
      ->getSchemaExtraTypesXml(),
    'schema_extra_fields.xml' => $this
      ->getSchemaExtraFieldsXml($backend
      ->getServer()),
    'solrconfig_extra.xml' => $this
      ->getSolrconfigExtraXml(),
  ];
  if (version_compare($solr_major_version, '7', '>=')) {
    $files['solrconfig_query.xml'] = $this
      ->getSolrconfigQueryXml();
    $files['solrconfig_requestdispatcher.xml'] = $this
      ->getSolrconfigRequestDispatcherXml();
  }

  // Add language specific text files.
  $list_builder = $this
    ->getListBuilder('solr_field_type');
  $solr_field_types = $list_builder
    ->getEnabledEntities();

  /** @var \Drupal\search_api_solr\SolrFieldTypeInterface $solr_field_type */
  foreach ($solr_field_types as $solr_field_type) {
    $text_files = $solr_field_type
      ->getTextFiles();
    foreach ($text_files as $text_file_name => $text_file) {
      $text_file_name = Utility::completeTextFileName($text_file_name, $solr_field_type);
      $files[$text_file_name] = $text_file;
      $solrcore_properties['solr.replication.confFiles'] .= ',' . $text_file_name;
    }
  }
  $solrcore_properties['solr.luceneMatchVersion'] = $connector
    ->getLuceneMatchVersion($this->assumedMinimumVersion ?: '');

  // @todo
  // $solrcore_properties['solr.replication.masterUrl']
  $solrcore_properties_string = '';
  foreach ($solrcore_properties as $property => $value) {
    $solrcore_properties_string .= $property . '=' . $value . "\n";
  }
  $files['solrcore.properties'] = $solrcore_properties_string;

  // Now add all remaining static files from the conf dir that have not been
  // generated dynamically above.
  foreach (scandir($search_api_solr_conf_path) as $file) {
    if (strpos($file, '.') !== 0) {
      foreach (array_keys($files) as $existing_file) {
        if ($file == $existing_file) {
          continue 2;
        }
      }
      $files[$file] = str_replace([
        'SEARCH_API_SOLR_MIN_SCHEMA_VERSION',
        'SEARCH_API_SOLR_BRANCH',
      ], [
        SolrBackendInterface::SEARCH_API_SOLR_MIN_SCHEMA_VERSION,
        $real_solr_branch,
      ], file_get_contents($search_api_solr_conf_path . '/' . $file));
    }
  }
  $connector
    ->alterConfigFiles($files, $solrcore_properties['solr.luceneMatchVersion'], $this->serverId);
  $this
    ->moduleHandler()
    ->alter('search_api_solr_config_files', $files, $solrcore_properties['solr.luceneMatchVersion'], $this->serverId);
  return $files;
}