You are here

function search_api_solr_server_get_files in Search API Solr 7

Retrieves a list of all config files of a server.

Parameters

SearchApiServer $server: The Solr server whose files should be retrieved.

string $dir_name: (optional) The directory that should be searched for files. Defaults to the root config directory.

Return value

array An associative array of all config files in the given directory. The keys are the file names, values are arrays with information about the file. The files are returned in alphabetical order and breadth-first.

Throws

SearchApiException If a problem occurred while retrieving the files.

1 call to search_api_solr_server_get_files()
search_api_solr_solr_config_form in ./search_api_solr.admin.inc
Form constructor for the Solr files overview.

File

./search_api_solr.module, line 274
Provides a Solr-based service class for the Search API.

Code

function search_api_solr_server_get_files(SearchApiServer $server, $dir_name = NULL) {
  $response = $server
    ->getFile($dir_name);

  // Search for directories and recursively merge directory files.
  $files_data = json_decode($response->data, TRUE);
  $files_list = $files_data['files'];
  $dir_length = strlen($dir_name) + 1;
  $result = array(
    '' => array(),
  );
  foreach ($files_list as $file_name => $file_info) {

    // Annoyingly, Solr 4.7 changed the way the admin/file handler returns
    // the file names when listing directory contents: the returned name is now
    // only the base name, not the complete path from the config root directory.
    // We therefore have to check for this case.
    if ($dir_name && substr($file_name, 0, $dir_length) !== "{$dir_name}/") {
      $file_name = "{$dir_name}/" . $file_name;
    }
    if (empty($file_info['directory'])) {
      $result[''][$file_name] = $file_info;
    }
    else {
      $result[$file_name] = search_api_solr_server_get_files($server, $file_name);
    }
  }
  ksort($result);
  ksort($result['']);
  return array_reduce($result, 'array_merge', array());
}