From e67bed3c824aaeb47f40832410cc5ce81cd14d49 Mon Sep 17 00:00:00 2001 From: Janette Day Date: Fri, 15 Mar 2024 10:47:47 -0500 Subject: [PATCH] so close --- .../src/Controller/QueryController.php | 17 +++++++++++++---- .../src/Unit/Controller/QueryControllerTest.php | 7 ++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/modules/datastore/src/Controller/QueryController.php b/modules/datastore/src/Controller/QueryController.php index 0318689c5d..2cc76df348 100644 --- a/modules/datastore/src/Controller/QueryController.php +++ b/modules/datastore/src/Controller/QueryController.php @@ -57,10 +57,19 @@ public function formatResponse( */ private function fixHeaderRow(RootedJsonData &$result) { try { - $schema = $result->{'$.schema'}; - // Query has are no explicit properties; we should assume one table. - $header_row = array_column(reset($schema)['fields'], 'description'); - + // if (!empty($result->{'$.query.properties'})) { + // $header_row = $result->{'$.query.properties'}; + // array_walk($header_row, function (&$header) { + // if (is_array($header)) { + // $header = $header['alias'] ?? $header['property']; + // } + // }); + // } + // else { + $schema = $result->{'$.schema'}; + // Query has are no explicit properties; we should assume one table. + $header_row = array_column(reset($schema)['fields'], 'description'); + // } if (empty($header_row) || !is_array($header_row)) { throw new \DomainException("Could not generate header for CSV."); } diff --git a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php index 23d7c2d70c..563e66f636 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php @@ -324,11 +324,16 @@ private function getQueryResult($data, $id = NULL, $index = NULL, $info = []) { */ public function testResourceQueryCsv() { $data = json_encode([ + "properties" => [ + [ + "resource" => "t", + "property" => "state", + ], + ], "results" => TRUE, "format" => "csv", ]); $result = $this->getQueryResult($data); - $this->assertTrue($result instanceof CsvResponse); $this->assertEquals(200, $result->getStatusCode()); }