From 61a8f5aed64e9aef4b0fdab40a22ab1eb1324107 Mon Sep 17 00:00:00 2001 From: Mark Unwin Date: Mon, 29 Jan 2018 13:27:47 +1000 Subject: [PATCH] Fix bug where we need to array_values data_order so when we json convert, we don't end up with a hash instead of an array because of a missing array element. --- .../application/helpers/output_helper.php | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/code_igniter/application/helpers/output_helper.php b/code_igniter/application/helpers/output_helper.php index a1a10baca..af30353c6 100644 --- a/code_igniter/application/helpers/output_helper.php +++ b/code_igniter/application/helpers/output_helper.php @@ -89,8 +89,10 @@ function output() } } else { + unset($CI->response->meta->data_order); + $CI->response->meta->data_order = array(); + if (!empty($CI->response->data)) { - $CI->response->meta->data_order = array(); foreach ($CI->response->data[0]->attributes as $key => $value) { $CI->response->meta->data_order[] = $key; } @@ -130,6 +132,7 @@ function output() } $CI->response->meta->data_order = array_unique($CI->response->meta->data_order); + $CI->response->meta->data_order = array_values($CI->response->meta->data_order); } @@ -254,7 +257,7 @@ function output_csv() $table = 'system'; } - #$CI->response->meta->data_order = array_values($CI->response->meta->data_order); + $CI->response->meta->data_order = array_values($CI->response->meta->data_order); $csv_header = $CI->response->meta->data_order; if ($CI->response->meta->collection != 'credentials' and $CI->response->meta->collection != 'discoveries' and @@ -326,18 +329,6 @@ function output_json() $filename = 'openaudit'; } - if (($CI->response->meta->collection == 'queries' and $CI->response->meta->action == 'execute') or - ($CI->response->meta->collection == 'devices' and $CI->response->meta->sub_resource == 'group') or - ($CI->response->meta->collection == 'summaries' and $CI->response->meta->action == 'execute')) { - if (!empty($CI->response->data)) { - unset ($CI->response->meta->data_order); - $CI->response->meta->data_order = array(); - foreach ($CI->response->data[0]->attributes as $key => $value) { - $CI->response->meta->data_order[] = $key; - } - } - } - header('Content-Type: application/json'); if ((string) $CI->config->item('download_reports') === 'download') { header('Content-Disposition: attachment;filename="'.$filename.'.json"');