wrap csv fields with string delimiter on export
This commit is contained in:
parent
5983333965
commit
e0090aee95
|
@ -6458,3 +6458,22 @@ function nms_check_api()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simply return a string enclosed in quote delimiter to be used in csv exports.
|
||||||
|
*
|
||||||
|
* @param string $str String to be formatted.
|
||||||
|
*
|
||||||
|
* @return string Formatted string.
|
||||||
|
*/
|
||||||
|
function csv_format_delimiter(?string $str)
|
||||||
|
{
|
||||||
|
if ($str === null) {
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Due to the ticket requirements, double quote is used as fixed string delimiter.
|
||||||
|
// TODO: a setup option that enables user to choose a delimiter character would probably be desirable in the future.
|
||||||
|
return '"'.$str.'"';
|
||||||
|
}
|
||||||
|
|
|
@ -166,11 +166,11 @@ try {
|
||||||
|
|
||||||
// Dump headers.
|
// Dump headers.
|
||||||
foreach ($names as $n) {
|
foreach ($names as $n) {
|
||||||
echo io_safe_output($n).$config['csv_divider'];
|
echo csv_format_delimiter(io_safe_output($n)).$config['csv_divider'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_metaconsole() === true) {
|
if (is_metaconsole() === true) {
|
||||||
echo 'server_id'.$config['csv_divider'];
|
echo csv_format_delimiter('server_id').$config['csv_divider'];
|
||||||
}
|
}
|
||||||
|
|
||||||
echo chr(13);
|
echo chr(13);
|
||||||
|
@ -203,21 +203,21 @@ try {
|
||||||
|
|
||||||
switch ($key) {
|
switch ($key) {
|
||||||
case 'module_status':
|
case 'module_status':
|
||||||
echo events_translate_module_status(
|
echo csv_format_delimiter(events_translate_module_status(
|
||||||
$row[$key]
|
$row[$key]
|
||||||
);
|
));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'event_type':
|
case 'event_type':
|
||||||
echo events_translate_event_type(
|
echo csv_format_delimiter(events_translate_event_type(
|
||||||
$row[$key]
|
$row[$key]
|
||||||
);
|
));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'criticity':
|
case 'criticity':
|
||||||
echo events_translate_event_criticity(
|
echo csv_format_delimiter(events_translate_event_criticity(
|
||||||
$row[$key]
|
$row[$key]
|
||||||
);
|
));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'custom_data':
|
case 'custom_data':
|
||||||
|
@ -244,11 +244,11 @@ try {
|
||||||
$custom_data = implode($separator, $custom_data_array);
|
$custom_data = implode($separator, $custom_data_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo io_safe_output($custom_data);
|
echo csv_format_delimiter(io_safe_output($custom_data));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
echo io_safe_output($row[$key]);
|
echo csv_format_delimiter(io_safe_output($row[$key]));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,7 +256,7 @@ try {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_metaconsole() === true) {
|
if (is_metaconsole() === true) {
|
||||||
echo $row['server_id'].$config['csv_divider'];
|
echo csv_format_delimiter($row['server_id']).$config['csv_divider'];
|
||||||
}
|
}
|
||||||
|
|
||||||
echo chr(13);
|
echo chr(13);
|
||||||
|
|
Loading…
Reference in New Issue