function apachesolr_config_files_overview in Apache Solr Search 7
Same name and namespace in other branches
- 8 apachesolr.admin.inc \apachesolr_config_files_overview()
- 6.3 apachesolr.admin.inc \apachesolr_config_files_overview()
- 6 apachesolr.admin.inc \apachesolr_config_files_overview()
- 6.2 apachesolr.admin.inc \apachesolr_config_files_overview()
Page callback to show available conf files.
Parameters
array $environment:
Return value
string A non-render array but plain theme output for the config files overview. Could be done better probably
1 string reference to 'apachesolr_config_files_overview'
- apachesolr_menu in ./
apachesolr.module - Implements hook_menu().
File
- ./
apachesolr.admin.inc, line 764 - Administrative pages for the Apache Solr framework.
Code
function apachesolr_config_files_overview(array $environment = array()) {
if (empty($environment)) {
$env_id = apachesolr_default_environment();
}
else {
$env_id = $environment['env_id'];
}
$xml = 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) {
apachesolr_log_exception($env_id, $e);
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)) {
continue;
}
// 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, array(
'query' => array(
'no_fast_404' => 1,
),
));
// 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(
'name' => t('File name'),
'date' => t('Modified'),
'size' => t('Size'),
);
// Display the table of field names, index types, and term counts.
$variables = array(
'header' => $header,
'rows' => $files,
);
$output = theme('table', $variables);
}
else {
$output = '<p>' . t('No data about any file found.') . "</p>\n";
}
return $output;
}