You are here

function apachesolr_config_files_overview in Apache Solr Search 6.3

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

Page callback to show available conf files.

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

File

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

Code

function apachesolr_config_files_overview($environment = NULL) {
  if (!$environment) {
    $env_id = apachesolr_default_environment();
  }
  else {
    $env_id = $environment['env_id'];
  }
  $xml = NULL;
  $output = NULL;
  try {
    $solr = apachesolr_get_solr($env_id);
    $response = $solr
      ->makeServletRequest('admin/file', array(
      'wt' => 'xml',
    ));
    $xml = simplexml_load_string($response->data);
  } catch (Exception $e) {
    watchdog('Apache Solr', nl2br(check_plain($e
      ->getMessage())), NULL, WATCHDOG_ERROR);
    drupal_set_message(nl2br(check_plain($e
      ->getMessage())), "warning");
  }
  if ($xml) {

    // Retrieve our items from the xml using xpath
    $items = $xml
      ->xpath('//lst[@name="files"]/lst');

    // Add all the data of the file in a files array
    $files = array();
    foreach ($items as $item_id => $item) {

      // Do not list directories. Always a bool
      if (isset($item->bool)) {
        break;
      }

      // Get data from the files.
      $name = (string) $item
        ->attributes() ? (string) $item
        ->attributes() : t('No name found');
      $files[$item_id]['name'] = l($name, 'admin/reports/apachesolr/' . $env_id . '/conf/' . $name);

      // Retrieve the date attribute
      if (isset($item->date)) {
        $modified = (string) $item->date
          ->attributes() == 'modified' ? (string) $item->date : t('No date found');
        $files[$item_id]['modified'] = format_date(strtotime($modified));
      }

      // Retrieve the size attribute
      if (isset($item->long)) {
        $size = (string) $item->long
          ->attributes() == 'size' ? (string) $item->long : t('No size found');
        $files[$item_id]['size'] = t('Size (bytes): @bytes', array(
          '@bytes' => $size,
        ));
      }
    }

    // Sort our files alphabetically
    ksort($files);

    // Initializes table header.
    $header = array(
      t('File name'),
      t('Modified'),
      t('Size'),
    );

    // Display the table of field names, index types, and term counts.
    $output .= theme('table', $header, $files);
  }
  else {
    $output = '<p>' . t('No data about any file found.') . "</p>\n";
  }
  return $output;
}